Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Java, using HttpPost (apache commons HttpClient) when sending JSON POST - should I URL encode the body?
    text
    copied!<p>I'm sending a RESTful JSON POST request using <a href="http://hc.apache.org/httpcomponents-client-ga/" rel="nofollow">Apache HttpClient</a> (to a 3rd party API)</p> <ul> <li><p>Should I URL encode the JSON body? </p></li> <li><p>And if something in the content is already URL encoded (e.g. I send HTML that has some links with URL encoded chars, e.g. @22) should I expect to get the content as is on the other side without it being decoded?</p></li> </ul> <p>E.g. if i'm doing something like this </p> <pre><code>String html = "&lt;a href='http://example.com?charOfTheDay=%22'&gt;click me&lt;/a&gt;"; // Build the JSON object JSONObject jsonObj = new JSONObject(); jsonObj.put("html", html); jsonObj.put("otherKey",otherValue); //... // Create the POST object and add the parameters HttpPost httpPost = new HttpPost(url); StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8); entity.setContentType("application/json"); httpPost.setEntity(entity); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(httpPost); </code></pre> <p>Should I expect getting the same value on the receiving end, after getting the value of the "html" key?</p> <p>e.g. on the receiving end</p> <pre><code>//after parsing the request string to a JSON object String html = inputJsonObject.get("html") // should return "&lt;a href='http://example.com?charOfTheDay=%22'&gt;click me&lt;/a&gt;" </code></pre> <p>Are there any other steps I need to do to make sure what I send is what is received "as is"?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload