In Java, using HttpPost (apache commons HttpClient) when sending JSON POST - should I URL encode the body?

前端 未结 2 1701
眼角桃花
眼角桃花 2021-01-03 07:46

I\'m sending a RESTful JSON POST request using Apache HttpClient (to a 3rd party API)

  • Should I URL encode the JSON body?

  • And if something i

2条回答
  •  一生所求
    2021-01-03 08:37

    The Content-Type in your http header should be application/json, so you oughtn't URL encode the body of the http request.

    URL encoding is meant to prevent users from using characters that are special in representing URLs (such as '/').

    You don't have to worry about links in the content being decoded either, unless you use a Content-Type in your http header that suggests that the server should decode the body, such as application/x-www-form-urlencoded

提交回复
热议问题