我正在尝试通过1个文件对象和2个文本提交POST请求,如下所示。但总是会得到 415不支持的媒体类型。我正在使用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);
有什么方法可以对其进行更多调试以获得确切的错误。