开发者

Passing JSON through the URI

开发者 https://www.devze.com 2022-12-27 13:18 出处:网络
I\'m trying to create a RE开发者_如何转开发ST based web service with data encapsulated using JSON. My problem is when I pass the string version of JSON in the URI it turns to something like this: %7B%

I'm trying to create a RE开发者_如何转开发ST based web service with data encapsulated using JSON. My problem is when I pass the string version of JSON in the URI it turns to something like this: %7B%22coal%22:100,%22ele%22:1500.1%7D.

I'm wondering if there are any functions Java for converting between the escaped and unescaped versions so I can parse the string.


You should be sending any content in the Request body. Only send query parameters in the URI.


Yep, use URLEncoder and/or URLDecoder.


That would be URLDecoder. But unless you are doing something wrong, you shouldn't have to use it, since methods in the Servlet API gnerally return already-decoded strings.


You are not supposed to decode URL escaped text, the web server does that by its own, it should be completely transparent to you.

As some people already pointed out you use URLDecode to unescape a URL string

If on some point of your code you are manually escaping the JSON string that's probably the issue as its getting encoded 2 times.


Your parameters are flat (no lists/objects/etc.).

  • For HTTP GET requests, try to pass the data as query parameters instead of encoded JSON
  • For HTTP POST requests, you won't have an encoding problem with JSON
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号