如何将以下curl请求添加到url格式?
HttpGet httpGetRequest = new HttpGet("curl -XGET 'localhost:9200/indexname/status/_search?pretty=1&size=10000' -d '{"_source": {"include": [ "ID", "Name" ]}}''"};
它现在抛出错误,因为它不是一个正确的http url格式。有什么建议?感谢。
答案 0 :(得分:0)
你的curl命令正在发送数据。您应该POST
用于此目的:
StringRequestEntity entity = new StringRequestEntity(
JSON_STRING,
"application/json",
"UTF-8");
PostMethod post = new PostMethod("http://example.com/action");
postMethod.setRequestEntity(entity);
int statusCode = httpClient.executeMethod(post);
如果您确实要发送包含请求正文的GET
,则需要创建自己的HttpEntityEnclosingRequestBase
子类。有关详细信息,请参阅Apache HttpClient GET with body。