I am sending a RESTful JSON POST request using Apache HttpClient (third-party API)
Should I encode the JSON body url?
And if something in the content is already encoded in the URL (for example, I am sending HTML code that has some links with URL-encoded characters, for example, @ 22), should I expect the content to be on the other side, decode?
eg. if i do something like this
String html = "<a href='http://example.com?charOfTheDay=%22'>click me</a>"; // 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);
Should I expect to receive the same value on the receiving side, after receiving the key value "html"?
eg. on the receiving side
Are there any other steps that I must follow to make sure that I send what is received "as is"?
source share