Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to POST XML/JSON??? #125

Closed
mustafa01ali opened this issue Oct 24, 2012 · 6 comments
Closed

How to POST XML/JSON??? #125

mustafa01ali opened this issue Oct 24, 2012 · 6 comments

Comments

@mustafa01ali
Copy link

I've run into a problem with POSTing data. I have to post data to the API in the following format: -

\<request\>
  \<notes\>Test api support\</notes\>
  \<hours\>3\</hours\>
  \<project_id type="integer"\>3\</project_id\>
\</request\>

As per the documentation, I tried doing it using RequestParams, but it is failing. Is this any other way to do it? I can POST equivalent JSON too. Any ideas?

@trippedout
Copy link

i believe if you just write your xml or json to a string and send to server, with proper headers or without, your server should be able to decode the string back into the proper format

@mustafa01ali
Copy link
Author

Thanks for replying.

I have to send this as the POST body, so which header should I use?

@trippedout
Copy link

should probably only need to set "Content-Type" to "application/json" but im no expert :)

@voidberg
Copy link

Here's an example:

// params is a JSONObject
StringEntity se = null;
try {
  se = new StringEntity(params.toString());
} catch (UnsupportedEncodingException e) {
  e.printStackTrace();
  return;
}
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));

client.post(null, getAbsoluteUrl(url), se, "application/json", responseHandler);

@doberdog doberdog mentioned this issue Jan 12, 2013
@smarek
Copy link
Member

smarek commented Oct 13, 2013

Closing with related referenced issue. using StringEntity is correct way to handle such situations.

@smarek smarek closed this as completed Oct 13, 2013
@shabbir-dhangot
Copy link

But What if I want to pass xml in body. @voidberg can you post some snippet regarding xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants