我正在尝试使用 1 个文件对象和 2 个提交如下文本的 POST 请求。但总是得到415 Unsupported Media Type。我正在使用 httpclient 4.4。
415错误是指正文或标题错误?
HttpPost request= new HttpPost("https://mysite/v1/files");
request.addHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");
request.addHeader("Authorization","Bearer <token>);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);`
File file = new File("/opt/productImages/productImage1.jpg");
builder.addTextBody("text", "productImage1.jpg", ContentType.TEXT_PLAIN);
builder.addTextBody("text", "productImage", ContentType.TEXT_PLAIN);
builder.addBinaryBody("upfile",uploadFile,ContentType.create("image/jpeg"),"productImage1.jpg");
HttpClient client = HttpClientBuilder.create().build();
HttpEntity entity = builder.build();
request.setEntity(entity);
HttpResponse response = client.execute(request);
System.out.println(response);
有什么方法可以对其进行更多调试以获得确切的错误。