jmeter Invalid UTF-8 middle byte

左心房为你撑大大i 提交于 2021-02-05 07:01:08

问题


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!


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/24629013/jmeter-invalid-utf-8-middle-byte

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!