Character Encoding in POST JSON Request

Vis picture Vis · Oct 14, 2015 · Viewed 67.7k times · Source

I am sending a POST JSON Request to my application.

POST /CharSetTest/Test HTTP/1.1
Host: localhost:8090
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 1637b92b-5896-4765-63c5-d04ad73ea9f1

{
  "SampleRequest": {
    "FullName": "関連当"
  }
}

My CXF JAXRS Consumer is defined as below.

@POST
@Produces("application/json; charset=UTF-8")
@Consumes("application/json; charset=UTF-8")
public Response testCharSet(@Encoded String jsonBody);

But the Japanese Character (関連当) that I sent as POST request is not encoded and results in some junk characters "é¢é£å½äºè"

Using SoapUI results in "?????" characters.

This Junk characters differs from client to client from where I hit the request. How Could I encode my POST Request ?

Answer

Rajat picture Rajat · Jan 29, 2016

Set the content-type to:

"application/json;charset=UTF-8" 

when sending the post request in the application you are using. You can find "content-type" in the Header of the URL in that application.