Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The response result of Jmeter is garbled and solved.

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Scene:

During the test, we may need to view the result tree, but we find that the response data in it has garbled characters in other forms except "Document". As shown in the following figure, the response data is set to be displayed in the form of Text, and the response data contains garbled characters:

Analysis: The reason is that the result processing code of Jmeter is inconsistent with the code of the tested object;

1. The default encoding method of sampler request result of Jmeter is ISO-8859-1 (Chinese is not supported);

2. The result code of the tested object may be gbk or UTF-8;

Solution:

1. Use the post-controller "BeanShell PostProcessor" to dynamically modify the result processing code to keep it consistent with the object under test;

Advantages: flexible, ready to modify;

Disadvantages: To set different encoding according to different objects,

Scope of application: test different company projects, some companies like GBK, some things UTF-8;

2. Modify the default code of Jmeter;

Advantages: once modified, long-term use;

Disadvantages: If you want to test different company projects, you need to modify them many times, which is more troublesome;

Scope of use: test the company's projects, after all, the same company's projects are basically using the same code;

Then it is very clear that everyone can set it according to their own needs.

The following describes the operational steps of both methods;

1. Use the rear controller "BeanShell PostProcessor"

(1) Determine the code of the returned result (you can confirm with the developer, if it is a web page, you can check the source file to know), such as;

(2) Right-click httpSampler and add "BeanShell PostProcessor" component;

(3) Set "BeanShell PostProcessor";

Add "prev.setDataEncoding(" UTF-8 ")" to "Script";"

(4) Verify whether it is solved, as shown in the figure below, and it has been successfully processed;

2. Modify the default encoding of Jmeter

(1) Go to %JmeterHome%/bin, find Jmeter.properties, and open it;

(2) Search for "sampler solution" and find the code setting code of sampler;

(3) Change the code to "UTF-8," remove the "#"(comment symbol), save the settings, and restart Jmeter;

(4) Verify whether it is solved, as shown in the following figure (no BeanShell PostProcessor), which has been successfully processed;

Extension:

1. When there is garbled code (usually Chinese) in the post request sent to the server,

content-encoding can be set in the request, such as UTF-8;

2. Does "BeanShell PostProcessor" have to be set in http request?

A: No, the post-processor is processed before the listener (if you don't know the scope and execution order of the component, please Google it yourself, I have time to sort it out later), so as long as it is in the scope, where the post-processor is placed is the same effect;

As shown below:

Reference Acknowledgement:

testtang jmeter response results garbled problem: www.cnblogs.com/tangmaokai/p/5830344.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report