[原創] web_custom_request 與 Viewstate

來源:互聯網
上載者:User

標籤:style   blog   http   io   os   ar   使用   for   sp   

  在用loadrunner對.net編寫的website進行效能測試時,經常會遇上一些hidden fields,例如,CSRFTOKEN、VIEWSTATE、EVENTVALIDATION等,而對於這些hidden field,有時候需要進行前後關聯。但是最近發現一個很奇怪的現象:已經通過web_reg_save_param_regexp函數準確的擷取了這些hidden fields,並且所得的param在web_submit_data可以正常使用,但是用在web_custom_request時卻總是報錯,百思不得其解!經過google後終於弄明白了:

進行關聯通常用到的都是web_reg_save_param、web_reg_save_param_ex、web_reg_save_param_regexp這三個函數,需要注意的是這三個函數拿回來的param的值都是html編碼的。

對於html編碼的param,web_submit_data函數可以直接使用,但是web_custom_request則不可以直接使用,而需要通過函數web_convert_param先轉換為url編碼才可以,否則是會產生error的。

 

int web_convert_param( const char *ParamName, [char *SourceString] char *SourceEncoding, char *TargetEncoding, LAST ); 

Example 1

The following example uses web_convert_param to convert HTML strings to URL and plain text formats.

The Web page has these texts:

Sample HTML code to be converted: <mytag>& End

Sample plain text to be converted: 1–AD X=0+2 End

Action()

{

web_reg_save_param("HTML",

    "LB=Sample HTML code to be converted: ",

    "RB= End",

    LAST );

 

web_reg_save_param("HTML1",

    "LB=Sample HTML code to be converted: ",

    "RB= End",

    LAST );

 

web_reg_save_param("Plaintext",

    "LB=Sample plain text to be converted: ",

    "RB= End",

    LAST );

 

web_url("web_url",

    "URL=http://lazyboy/html/convert_param_page.html",

     "TargetFrame=",

    "Resource=0",

     "Referer=",

     LAST );

 

web_convert_param("HTML", "SourceEncoding=HTML",

     "TargetEncoding=URL", LAST );

web_convert_param("HTML1", "SourceEncoding=HTML",

     "TargetEncoding=PLAIN", LAST );

web_convert_param("Plaintext", "SourceEncoding=HTML",

     "TargetEncoding=URL", LAST );

 

web_reg_save_param("Result",

    "LB=<code>entry = ",

    "RB=</code>",

    LAST );

 

web_custom_request("web_custom_request",

    "URL=http://lazarus/cgi–bin/post_query.exe",

    "Method=POST",

    "TargetFrame=",

    "Resource=0",

    "Referer=",

    "Body=entry={Plaintext},{HTML}",

    LAST );

return 0;

}

The following section shows the relevant sections of the log file that resulted from running the above segment:

Running Vuser...

Action.c(21): Saving Parameter "HTML = &lt;mytag&gt;&amp;"

Action.c(21): Saving Parameter "HTML1 = &lt;mytag&gt;&amp;"

Action.c(21): Saving Parameter "Plaintext = 1–AD X=0+2"

After web_url:

Action.c(28): Saving Parameter "HTML = %3Cmytag%3E%26"

Action.c(28): web_convert_param was successful

Action.c(29): Saving Parameter "HTML1 = <mytag>&"

Action.c(29): web_convert_param was successful

Action.c(30): Saving Parameter "Plaintext = 1–AD+X%3D0%2B2"

Action.c(30): web_convert_param was successful

web_custom_request:

Action.c(37): Parameter Substitution: parameter "Plaintext" = "1–AD+X%3D0%2B2"

Action.c(37): Parameter Substitution: parameter "HTML" = "%3Cmytag%3E%26"

Action.c(37): Saving Parameter "Result = 1–AD X=0+2,<mytag>&"

Example 2

This example shows the use of the SourceString argument. Note that the source string can contain parameters. The source string is first evaluated, replacing parameters with their values, then converted to PLAIN. The result is stored in parameter "targetParam."

web_convert_param(

        "targetParam",

        "SourceString={param1}abc{param2}",

        "SourceEncoding=HTML",

        "TargetEncoding=PLAIN",

         LAST ); 

[原創] web_custom_request 與 Viewstate

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.