|
[原创] web_convert_param 函数应用
选取web 协议,用html方式录制baidu.com查询”linux技巧”,则在runtime-viewer回放看到查询关键词并非”linux技巧”而是URL编码结果。
改用url 模式录制,代码如后:
web_url("s",
"URL=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
web_url("c.gif",
"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Mode=HTTP",
LAST);
回放出错,经ethreal截包,确有:http 204错误。
Action.c(28): Error -26563: Non-empty response body is invalid with HTTP Status Code 204 (No Content) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"
[MsgId: MERR-26563]
Action.c(28): t=1560ms: 1-byte response body for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9" (RelFrameId=1)
Action.c(28):
\x00
Action.c(28): Warning -26652: Response body length (1) does not match the Content-Length header specification (0) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"
[MsgId: MWAR-26652]
Action.c(28): web_url("c.gif") highest severity level was "ERROR", 1 body bytes, 112 header bytes
[MsgId: MMSG-26388]。
为了参数化以及更正错误,正确的代码如后:
web_convert_param("encoderesult", "SourceString={keyword}","SourceEncoding=HTML",
"TargetEncoding=URL", LAST);
lr_log_message("encode=%s",lr_eval_string("{encoderesult}"));
web_url("s",
"URL=http://www.baidu.com/s?wd={encoderesult}&cl=3",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
lr_continue_on_error(LR_ON_ERROR_CONTINUE );
web_url("c.gif",
"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Mode=HTTP",
LAST);
选取web 协议,用html方式录制baidu.com查询”linux技巧”,则在runtime-viewer回放看到查询关键词并非”linux技巧”而是URL编码结果。
改用url 模式录制,代码如后:
web_url("s",
"URL=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
web_url("c.gif",
"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Mode=HTTP",
LAST);
回放出错,经ethreal截包,确有:http 204错误。
Action.c(28): Error -26563: Non-empty response body is invalid with HTTP Status Code 204 (No Content) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"
[MsgId: MERR-26563]
Action.c(28): t=1560ms: 1-byte response body for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9" (RelFrameId=1)
Action.c(28):
\x00
Action.c(28): Warning -26652: Response body length (1) does not match the Content-Length header specification (0) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"
[MsgId: MWAR-26652]
Action.c(28): web_url("c.gif") highest severity level was "ERROR", 1 body bytes, 112 header bytes
[MsgId: MMSG-26388]。
为了参数化以及更正错误,正确的代码如后:
web_convert_param("encoderesult", "SourceString={keyword}","SourceEncoding=HTML",
"TargetEncoding=URL", LAST);
lr_log_message("encode=%s",lr_eval_string("{encoderesult}"));
web_url("s",
"URL=http://www.baidu.com/s?wd={encoderesult}&cl=3",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST);
lr_continue_on_error(LR_ON_ERROR_CONTINUE );
web_url("c.gif",
"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",
"Mode=HTTP",
LAST); |
|