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