How to solve the Java Protocol LoadRunner script return string garbled problem

Source: Internet
Author: User

When writing the Java Protocol's LoadRunner script, the server occasionally returns partial Chinese characters, which are garbled when printed directly in the log and need to be escaped. The reason is that the actual returned character is in UTF-8 format, but LoadRunner is used in the GB2312 format, using the string constructor string (byte b[], "encoding") to transcode two times.

Here's the code:

Web.reg_save_param ("msg",Newstring[]{"Notfound=error",                    "lb=msg\ ": \"","rb=\ ", \" Data"," Last" });            Autoaddheader (); Web.url ("Index",            "url="+Host+"/index?token=<token>&doctorid=<doctorid>",            NewString[] {"targetframe=","resource=0",                "Reccontenttype=application/json","Snapshot=t1.inf",                "mode=html"," Last" }); String message=NewString (Lr.eval_string ("<msg>"). GetBytes (),"UTF-8");//first escape into UTF-8 encoded String gb2312=NewString (Message.getbytes ("GB2312") ;//Get the encoded character lr.output_message (gb2312) in GB2312 format;

Note that two escapes are required here, one escape cannot be done, and the pit is resolved several times.

How to solve the Java Protocol LoadRunner script return string garbled problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.