如何将curl命令转换为javaapachehttppost?
我不知道如何将下面curl命令的某些元素(例如-L或任何布尔/开关变量)参数复制到JavaHTTPPOST curl命令:如何将curl命令转换为javaapachehttppost?,java,curl,http-post,apache-httpclient-4.x,apache-httpcomponents,Java,Curl,Http Post,Apache Httpclient 4.x,Apache Httpcomponents,我不知道如何将下面curl命令的某些元素(例如-L或任何布尔/开关变量)参数复制到JavaHTTPPOST curl命令: curl -L -XPOST localhost:4001/db?pretty -d 'some data' 迄今为止,httppost: CloseableHttpClient httpClient=HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build(); Htt
curl -L -XPOST localhost:4001/db?pretty -d 'some data'
迄今为止,httppost:
CloseableHttpClient httpClient=HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
HttpPost httpPost = new HttpPost(postURL);
httpPost.setEntity(new StringEntity(someData));
// httpPost.setEntity(new StringEntity("L")); This doesn't work
ResponseHandler<String> handler = new BasicResponseHandler();
CloseableHttpResponse response = httpClient.execute(httpPost);
message = handler.handleResponse(response);
CloseableHttpClient-httpClient=HttpClientBuilder.create().setRedirectStrategy(新的laxrirectStrategy()).build();
HttpPost HttpPost=新的HttpPost(姿态);
setEntity(新的StringEntity(someData));
//httpPost.setEntity(新的StringEntity(“L”));这不管用
ResponseHandler=new BasicResponseHandler();
CloseableHttpResponse response=httpClient.execute(httpPost);
message=handler.handleResponse(响应);
提前感谢。首先,您必须了解参数在curl中的作用。在理解了这个概念之后,您应该寻找如何使用框架实现该功能。curl上的-X是指Stream,因此您需要使用
InputStreamEntity
而不是StringEntity