2
votes

I'm using jMeter to shoot json through post requests to my test server.

the following request always fail:

{
    "location": {
        "latitude": "37.390737",
        "longitude": "-121.973864"
    },
    "category": "Café & Bakeries"
}

the error message in the response data is:

Invalid UTF-8 middle byte 0x20
 at [Source: org.apache.catalina.connector.CoyoteInputStream@6073ddf0; line: 6, column: 20]

The request is not sent to the server at all. other requests (e.g. replacing the value in category with other valid category like "Delis") works perfectly.

I guess it's an encoding issue related to "Café" but I don't know how to resolve it. any idea? Thanks!

3

3 Answers

6
votes

in the HTTP request itself, it is possible to set "content encoding". I set there "utf-8" and it solved the problem

1
votes

You'll probably need an HTTP header to post that JSON:

Content-Type: application/json; charset=utf-8

Without this, it's likely that the string isn't UTF-8–encoded. JSON should be in UTF-8, so the hex bytes for é should be 0xc3 0xa9.

Without that header, the byte sequence is probably 0xe9, which is in ISO-8859-1 encoding. That would explain the error, as UTF-8 sequences starting 0xe_ are 3-byte sequences, so it sees 0xe9 0x20 (where 0x20 is the space after the é) and complains about an "invalid middle byte".

Source: Posting a JSON request with JMeter

0
votes

None of the above solutions worked for me in jmeter 5.2.1

What I tried?

  1. Set the jmeter properties file: sampleresult.default.encoding=UTF-8 (Didn't work)
  2. Set the header Content-Type=application/json;UTF-8 ( Didn't work)
  3. Tried preProcessor sampler.getArguments().getArgument(0).setValue(new String(utf8Bytes)) ( Didn't work)
  4. Fortunately I noticed a field "Content encoding" ( As mentioned by Ofir Kolar) which seem to worked finally

enter image description here