0

How to add the following curl request into a url format?

HttpGet httpGetRequest = new HttpGet("curl -XGET 'localhost:9200/indexname/status/_search?pretty=1&size=10000' -d '{"_source": {"include": [ "ID", "Name" ]}}''"};

It's throwing error now as its not a proper http url format. Any advice? Thanks.

Sweet
  • 187
  • 3
  • 15
  • Are you wanting to use `cURL` or are you wanting to actually use `HttpGet`? If you want to use `cURL`, use `java.lang.Runtime.getRuntime().exec()` to invoke it, or as it seems to be, you are wanting to actually use `HttpGet`, please drop the "`curl -XGET`" from your string. – Ken Y-N Mar 28 '16 at 23:38
  • 1
    Looks like you have nested quotes... you'll probably need to escape them. – billjamesdev Mar 28 '16 at 23:38
  • If I drop the curl -XGET, it's not a proper url. Thats my question too. How will I change that request to a Proper URL that I can enter inside the httget method? – Sweet Mar 28 '16 at 23:58

1 Answers1

0

Your curl command is sending data. You should use POST for such purpose:

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

In case you really want to send a GET containing a request body you need to create your own subclass of HttpEntityEnclosingRequestBase. See Apache HttpClient GET with body for details.

Community
  • 1
  • 1
Sebastian
  • 16,813
  • 4
  • 49
  • 56