Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将curl命令转换为javaapachehttppost?_Java_Curl_Http Post_Apache Httpclient 4.x_Apache Httpcomponents - Fatal编程技术网

如何将curl命令转换为javaapachehttppost?

如何将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或任何布尔/开关变量)参数复制到JavaHTTPPOST

curl命令:

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