我似乎沒有從 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
提交
取消