Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character Encoding in POST JSON Request

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 ?

like image 470
Vis Avatar asked Oct 14 '15 14:10

Vis


People also ask

Is JSON ASCII or UTF-8?

The default encoding is UTF-8, and JSON texts that are encoded in UTF-8 are interoperable in the sense that they will be read successfully by the maximum number of implementations; there are many implementations that cannot successfully read texts in other encodings (such as UTF-16 and UTF-32).

Is JSON UTF-8 or UTF-16?

(in §3) JSON text SHALL be encoded in Unicode. The default encoding is UTF-8. (in §6) JSON may be represented using UTF-8, UTF-16, or UTF-32. When JSON is written in UTF-8, JSON is 8bit compatible.

How can I pass UTF-8 in Postman?

Hi, You can manually add the Content-Type header and it will override the generated one. Go into the "Headers" tab for the request and add a new header. Name it "Content-Type" (without the quotes) and set the value to "text/xml; charset=utf-8" (again, no quotes).


1 Answers

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.

like image 127
Rajat Avatar answered Sep 25 '22 06:09

Rajat