以前一直没有解决的问题,利用LoadRunner测试一个应用的时候,需要验证域用户,所以即使录制成功,每次回放的时候都提示错误,用户名和密码不对,对此耿耿于怀了很久。今天居然解决了。解决方法就是一个简单的函数调用: web_set_user,此函数的解释和用法如下:

The web_set_user function is a Service function that specifies a login string and password for a Web server or proxy server. It can be called more than once if several proxy servers require authentication. web_set_user overrides the run-time proxy authentication settings for user name and password.

When you log onto a server that requires user and password validation, VuGen records a web_set_user statement containing the login details. However, there are some more stringent, authentication methods for which VuGen is unable to insert web_set_user statements. See User Authentication for more detail. In such cases, you can add web_set_user into your script manually.

When you run the script, LoadRunner automatically submits the user authorization along with every subsequent request to that server. At the end of the script, LoadRunner resets the authorization.

This function is supported for all Web Vusers, and for WAP Vusers running in HTTP mode only. It is not supported for WAP Vusers running in Wireless Session Protocol (WSP) replay mode.

Example 3
The following example was inserted manually by the user into the script as the Web server “mansfield” uses NTLM authentication. VuGen cannot record NTLM or Digest authentication. Note that for NTLM authentication the domain name “mansfield” followed by a double backslash must be prepended to the user name:

web_set_user(“mansfield\\freddy”, “XYZ”, “mansfield:80”);


验证码如下: 52|52|52|51|46|47|49|55|
对应界面的验证码是: 6039

#include “web_api.h”


// char* str = “52|52|52|51|46|47|49|55|”;
char result[64];
int num1;
int num2;
int num3;
int num4;

int temp1;
int temp2;
int temp3;
int temp4;


web_reg_save_param(“check”, “LB=Image=”, “RB=\\”, LAST);


lr_think_time( 6 );

sscanf(lr_eval_string(“{check}”), “%d|%d|%d|%d|%d|%d|%d|%d”, &temp1, &num1, &temp2, &temp3, &num2, &temp4, &num3, &num4);

num1 -= 46;
num2 -= 46;
num3 -= 46;
num4 -= 46;

sprintf(result, “%d%d%d%d”, num1, num2, num3, num4);

lr_log_message(“getvalue : %s”, result);

“Name=Register.reason”, “Value= “, ENDITEM,
“Name=set_attach”, “Value=result”, ENDITEM,

return 0;

This entry was posted in 测试工具. Bookmark the permalink.

One Response to LoadRunner案例分析之三

  1. Jackei says:

    强!这种规律都可以发现 ^_^

Leave a Reply to Jackei Cancel reply

Your email address will not be published. Required fields are marked *