我正在尝试使用apachehttpclient将post请求发送到我的服务器。post请求将向服务器发送一个文本文件。服务器将对该文本文件的内容执行一些操作。
但我收到了400个坏请求。
final byte[] file = new byte[(int) flowFile.getSize()];
...
CloseableHttpClient httpclient = HttpClients.createDefault();
MultipartEntityBuilder entitybuilder = MultipartEntityBuilder.create();
entitybuilder.addBinaryBody(fileName, file, ContentType.DEFAULT_BINARY, fileName);
HttpEntity mutiPartHttpEntity = entitybuilder.build();
RequestBuilder reqbuilder = RequestBuilder.post("http://0.0.0.0:3333/predict");
reqbuilder.setEntity(mutiPartHttpEntity);
HttpUriRequest multipartRequest = reqbuilder.build();
HttpResponse httpresponse = httpclient.execute(multipartRequest);
StatusLine status = httpresponse.getStatusLine();
我该怎么修?我添加文本文件的代码有问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!