0

I'm trying to access an API which returns Json content with query params through Apache http post. The endpoint works fine on the browser but my post request is completely ignoring the query params. It works completely fine on the browser.

HttpPost post = new HttpPost(url);// http://hostname:port/type/endpoint1
post.addHeader("content-type","text/plain");
post.addHeader("Accept","text/plain");
post.setEntity(new StringEntity("?key=value"));
response = client.execute(post);

This returns the response only for url. And is completely ignoring the params.

Tejashwini
  • 95
  • 1
  • 12
  • Does this mean you wish to have your HTTP Body with this content `post.setEntity(new StringEntity("?key=value"))` – piy26 May 14 '18 at 07:26
  • @Berger My understanding is the linked question asks about server accepting JSON, while this question is about server accepting query params through POST. – Jiri Tousek May 14 '18 at 07:34

1 Answers1

1

Change your content-type to application/x-www-form-urlencoded, and remove the leading ? from the body.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43