我发现了问题。我需要向我添加一个
AbstractResource(在本例中为
ByteArrayResource),
MultiValueMap而不是原始字节数组。这是修复它的代码:
public void scaleImage(byte[] image, float percent) throws Exception { String url = "http://localhost:8080/scale/" + percent; final byte[] rawBytes = image.clone(); MultiValueMap<String, Object> mvm = new linkedMultiValueMap<>(); ByteArrayResource bar = new ByteArrayResource(rawBytes) { @Override public String getFilename() { return "Test-"+rawBytes.length + ".jpg"; } }; mvm.add("file", bar); TransformedResponse r = doPost(url, mvm);}

![将带有Spring RestTemplate的byte []上传到SpringMVC rest端点时出现400错误的请求 将带有Spring RestTemplate的byte []上传到SpringMVC rest端点时出现400错误的请求](http://www.mshxw.com/aiimages/31/443262.png)
