我似乎没有从httpclient获得整个json响应。我遇到了像这样在本地运行的api:
curl -i -X POST http://localhost:8098/<api location> -F "files=@<filename>"
我的回答如下:
{"data":[<bunch of json>]
但是当我尝试使用httpclients发布完全相同的文件时,会收到以下响应:
{"data":[]}
我在做什么错?这是我的Java代码。谢谢!
public CloseableHttpResponse submit (File file) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(API_LOCATION + API_BASE);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("ISO xml file", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
HttpEntity multipartEntity = builder.build();
post.setEntity(multipartEntity);
CloseableHttpResponse response = client.execute(post);
System.out.println("response: " + IOUtils.toString(response.getEntity().getContent(),"UTF-8"));
client.close();
return response;
}