我有多个重定向到登录页面的网站。重定向的数量可能会有所不同,我通过以下方式解决了它:
<transaction name="get_login_page">
<request>
<dyn_variable name="redirect" re="Location: ((http|https)://.*)\r"/>
<http url='/' version='1.1' method='GET'>
</http>
</request>
<repeat name="redirect_loop" max_repeat="5">
<request subst="true">
<dyn_variable name="redirect" re="Location: ((http|https)://.*)\r"/>
<http url="%%_redirect%%" method="GET"></http>
</request>
<until var="redirect" eq=""/>
</repeat>
</transaction>
从这一点开始我遇到了一个问题,因为在登录页面上我必须将数据提交到当前 URL,但是在最后一次迭代变量“redirect”之后变为空。我试图在循环中创建带有条件的附加变量以保存最后一个非空值:
<transaction name="get_login_page">
<request>
<dyn_variable name="redirect" re="Location: ((http|https)://.*)\r"/>
<http url='/' version='1.1' method='GET'>
</http>
</request>
<repeat name="redirect_loop" max_repeat="5">
<request subst="true">
<dyn_variable name="redirect" re="Location: ((http|https)://.*)\r"/>
<if var="redirect" eq=''>
<dyn_variable name="login_url" re="Location: ((http|https)://.*)\r"/>
</if>
<http url="%%_redirect%%" method="GET"></http>
</request>
<until var="redirect" eq=""/>
</repeat>
</transaction>
但是现在我在 tsung run 上有一个错误:
Starting Tsung
"Log directory is: /home/***/login_portal/logs/20141103-0945"
594- fatal: {failed_validation,element_unauthorize_in_choice}
Config Error, aborting ! {{badmatch,
{<<"<arrivalphase phase=\"1\" duration=\"5\" unit=\"second\">\n <users maxnumber=\"1\" arrivalrate=\"1\" unit=\"second\"></users>\n</arrivalphase>\n">>,
{xmerl_sax_parser_state,undefined,
#Fun<xmerl_sax_parser.1.53952608>,
{file_descriptor,prim_file,
{#Port<0.1047>,13}},
#Fun<xmerl_sax_parser.default_continuation_cb.1>,
utf8,1,
[{"xml",
"http://www.w3.org/XML/1998/namespace"}],
[],[],true,69656,no,normal,
"/home/***/login_portal/.",
"tsung_config_load.xml",false}}},
[{xmerl_sax_parser_utf8,handle_external_entity,2,
[{file,"xmerl_sax_parser_utf8.erl"},
{line,1692}]},
{xmerl_sax_parser_utf8,parse_external_entity,3,
[{file,"xmerl_sax_parser_utf8.erl"},
{line,1670}]},
{xmerl_sax_parser_utf8,parse_content,4,
[{file,"xmerl_sax_parser_utf8.erl"},
{line,1157}]},
{xmerl_sax_parser_utf8,parse_document,2,
[{file,"xmerl_sax_parser_utf8.erl"},
{line,179}]},
{xmerl_sax_parser_utf8,parse,2,
[{file,"xmerl_sax_parser_utf8.erl"},
{line,115}]},
{xmerl_sax_parser,file,2,
[{file,"xmerl_sax_parser.erl"},{line,77}]},
{ts_config,read,2,
[{file,"src/tsung_controller/ts_config.erl"},
{line,77}]},
{ts_config_server,handle_call,3,
[{file,
"src/tsung_controller/ts_config_server.erl"},
{line,206}]}]}
有没有办法获取最后访问的 URL 或使用内置函数从 DOM 模型中获取它?或者我应该如何创造条件让它正常工作?