如何将curl命令转换为java apache HttpPost?

时间:2015-04-13 15:53:24

标签: java curl http-post apache-httpclient-4.x apache-httpcomponents

我无法弄清楚如何将以下curl命令的某些元素(例如-L或任何boolean / switch变量)复制到java http post

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);

提前致谢。

0 个答案:

没有答案