While working with jmeter, I faced an issue of character encoding in http sampler request.
My problem:
I had to send a POST request with json request body , which had different characters from different languages.
I was able to send request successfully using postman but the same request when I added to jmeter, it was throwing below error:
Invalid UTF-8 middle byte 0x3f
I tried to searching on web but none of the solutions worked.
What did I try?
- Set the jmeter properties file: sampleresult.default.encoding=UTF-8 (Didn’t work)
- Set the header Content-Type=application/json;UTF-8 ( Didn’t work)
- Tried preProcessor ( Didn’t work)
def requestBody = sampler.getArguments().getArgument(0).getValue();
byte[] utf8Bytes = requestBody.getBytes("UTF-8");
sampler.getArguments().getArgument(0).setValue(new String(utf8Bytes));
Then I found a field in http request screen, Content encoding. ( Silly than I didn’t see at first, but it worked )

Sometimes, the solution lies in front of eyes but we keep searching for it somewhere else 🙂
🙂
LikeLiked by 1 person