HTTP/1.1 401 未授权响应 Headers 在 GET 请求的加载运行器中

HTTP/1.1 401 Unauthorized in Response Headers in Load runner for GET Requests

我是 Load runner 的新手,在回放脚本时遇到问题

LR 12.50

O.S Windows 7 SP2

协议是移动的HTTP/HTML

录制模式为Proxy

让我解释一下我的情况

执行以下函数时:

  web_custom_request("authenticate", 

        "URL=https://ws-xx.xxx.com/tcs/rest/authenticate?include=user,company",     
        "Method=POST", 
        "Resource=0", 
        "RecContentType=application/json", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTTP", 
        "EncType=application/json",
        "Body={\"password\":\"xxx\",\"username\":\"xxx\",\"version\":\"1.0.40\"}", 
        LAST);

对于上述 POST 方法,得到的响应如下

   HTTP/1.1 200 OK\r\n
   Date: Tue, 13 Oct 2015 19:19:21 GMT\r\n
   Server: Apache-Coyote/1.1\r\n
   Content-Type: application/json\r\n
   Set-Cookie: dtCookie=DBE9311E44E5C47902702DC762030583|TXlBcHB8MQ; Path=/;
   Domain=.xxx.com\r\n    
   Connection: close\r\n
   Transfer-Encoding: chunked\r\n

很好,现在第二个自定义请求如下所示

  web_custom_request("profiles", 
        "URL=https://ws-test.xxx.com/tcs/rest/profiles", 
        "Method=GET", 
        "Resource=1", 
        "RecContentType=application/json", 
        "Referer=", 
        "Snapshot=t2.inf", 
        LAST);

对于重播日志中的上述 GET 请求,我得到:

401 unauthorized error.

 GET /tcs/rest/profiles HTTP/1.1\r\n

     User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT)\r\n

    Accept: */*\r\n

    Connection: Keep-Alive\r\n

     Host: ws-test.xxx.com\r\n

   Cookie: dtCookie=DBE9311E44E5C47902702DC762030583|TXlBcHB8MQ\r\n
\r\n
 t=5921ms: 172-byte response headers for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)

    HTTP/1.1 401 Unauthorized\r\n

   Date: Tue, 13 Oct 2015 19:19:22 GMT\r\n

   Server: Apache-Coyote/1.1\r\n

   Content-Type: application/json\r\n

    Connection: close\r\n

    Transfer-Encoding: chunked\r\n
   \r\n

t=5922ms: 4-byte chunked response overhead for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)
    8b\r\n

 t=5923ms: 139-byte chunked response body for "https://ws-test.xxx.com/tcs/rest/profiles" (RelFrameId=1, Internal ID=2)
     {"errors":[{"message":"Authentication required to access endpoint","status":"401","code":"



 NotAuthenticated","header":"Not Authenticated"}]}

我审阅了 this link

根据上面的自定义请求我的理解,登录成功但是接下来 后续请求失败。

我使用了 web_cleanup_cookies() 函数,但没有解决问题。

我尝试使用以下函数捕获 Cookie ID

web_reg_save_param("COOKIE_ID",
                        "LR= Cookie: dtCookie=" ,
                        "RB= |TXlBcHB8MQ\r\n",
                        "Ord=All",
                        "RelFrameId=1",
                        "Search=All",
                        LAST);

web_add_header("Cookie",lr_eval_string("{COOKIE_ID}"));

现在的问题是在我的脚本中哪里放置参数 "COOKIE_ID" 而有

COOKIE_ID 的脚本中没有值?

如何处理这个问题?谁能帮帮我。

请在脚本中添加以下 headers

web_set_sockets_option("SSL_VERSION","TLS");
web_set_user("username", "password", "domain:portno" );
web_set_sockets_option("INITIAL_BASIC_AUTH","1");
  1. 在 Vugen 中,Select 快照查看并比较记录和重放请求,怀疑重放请求中可能缺少 header。
  2. 如果 cookie 是唯一改变的东西,您可以使用 web_add_cookie 函数添加它。