[英]How to set 'Referer' HTTP header using Apache HttpComponents HttpClient
[英]How to execute a search template within Elasticsearch by using apache.httpcomponents.httpclient
curl -XGET http://localhost:9200/contact/_search/template?pretty -d '{"id":"contact", "params": {"q": "123456", "company": "2"}}'
它工作正常,但是如何使用httpclient進行此調用?
您可以像這樣輕松實現:
StringRequestEntity entity = new StringRequestEntity(
"{\"id\":\"contact\", \"params\": {\"q\": \"123456\", \"company\": \"2\"}}",
"application/json",
"UTF-8");
PostMethod post = new PostMethod("http://localhost:9200/contact/_search/template");
postMethod.addParameter("pretty", "");
postMethod.setRequestEntity(entity);
int statusCode = httpClient.executeMethod(post);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.