我似乎没有从 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;}
1 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
添加回答
举报
0/150
提交
取消