我似乎没有从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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句