• jmeter-对响应数据进行unicode转码


    1,请求接口成功后,返回数据为unicode编码,查看不方便

    2.添加BeanShell PostProcessor,插入代码

     1 String s=new String(prev.getResponseData(),"UTF-8");
     2         char aChar;
     3         int len= s.length();
     4         StringBuffer outBuffer=new StringBuffer(len);
     5         for(int x =0; x <len;){
     6             aChar= s.charAt(x++);
     7             if(aChar=='\'){
     8                 aChar= s.charAt(x++);
     9                 if(aChar=='u'){
    10                     int value =0;
    11                     for(int i=0;i<4;i++){
    12                         aChar= s.charAt(x++);
    13                         switch(aChar){
    14                             case'0':
    15                             case'1':
    16                             case'2':
    17                             case'3':
    18                             case'4':
    19                             case'5':
    20                             case'6':
    21                             case'7':
    22                             case'8':
    23                             case'9':
    24                                 value=(value <<4)+aChar-'0';
    25                                 break;
    26                             case'a':
    27                             case'b':
    28                             case'c':
    29                             case'd':
    30                             case'e':
    31                             case'f':
    32                                 value=(value <<4)+10+aChar-'a';
    33                                 break;
    34                             case'A':
    35                             case'B':
    36                             case'C':
    37                             case'D':
    38                             case'E':
    39                             case'F':
    40                                 value=(value <<4)+10+aChar-'A';
    41                                 break;
    42                             default:
    43                                 throw new IllegalArgumentException(
    44                                         "Malformed   \uxxxx  encoding.");}}
    45                     outBuffer.append((char) value);}else{
    46                     if(aChar=='t')
    47                         aChar='	';
    48                     else if(aChar=='r')
    49                     aChar='
    ';
    50                     else if(aChar=='n')
    51                     aChar='
    ';
    52                     else if(aChar=='f')
    53                     aChar='f';
    54                     outBuffer.append(aChar);}}else
    55                 outBuffer.append(aChar);}
    56         prev.setResponseData(outBuffer.toString());
    View Code

    保存,运行

    转码成功

  • 相关阅读:
    bzoj 1497: [NOI2006]最大获利
    bzoj 2733: [HNOI2012]永无乡
    [CF911G]Mass Change Queries
    [CF911F]Tree Destruction
    [CF911E]Stack Sorting
    [CF911D]Inversion Counting
    [CF911C]Three Garlands
    [CF911B]Two Cakes
    [CF911A]Nearest Minimums
    [POJ1201]Intervals
  • 原文地址:https://www.cnblogs.com/jescs/p/7116612.html
Copyright © 2020-2023  润新知