我正在使用Apache HttpClient发送一个 RESTful JSON POST 请求(到第 3 方 API)
我应该对 JSON 正文进行 URL 编码吗?
如果内容中的某些内容已经经过 URL 编码(例如,我发送的 HTML 包含一些带有 URL 编码字符的链接,例如 @22),我是否应该期望在另一端获得内容而不对其进行解码?
例如,如果我正在做这样的事情
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);
在获得“html”键的值之后,我是否应该期望在接收端获得相同的值?
例如在接收端
//after parsing the request string to a JSON object
String html = inputJsonObject.get("html")
// should return "<a href='http://example.com?charOfTheDay=%22'>click me</a>"
我需要做任何其他步骤来确保我发送的内容是“按原样”接收的吗?