如何使用Java将JSON数据发布到服务器

问题描述:

我正在尝试建立一个POST请求,以使用REST API将JSON数据发送到服务器.

I am trying to build a POST request to send JSON data to a server using a REST api.

由于JSON代码将作为请求参数值嵌入在请求主体中,因此我需要对值进行编码以转义通常在JSON语法中找到的特殊字符,例如'{} []'.

As the JSON code will be embedded in the request body as a request parameter value, do I need to encode the value to escape special characters like '{}[]' you typically find in JSON syntax.

有没有实用程序库可以做到这一点?

Is there any utility library to do that ?

N.

请求的正文无需进行URL编码.看看 HttpClient .它是发出POST请求的事实库.

The body of the request needs not to be URL encoding. Have a look at HttpClient. It is the de-facto library for issuing POST requests.