简体   繁体   English

HTTP / 1.1 401未经授权在LoadRunner的响应标头中进行GET请求

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

I am new to Load runner , Am facing am issue while play back of the script 我是LoadRunner的新手,播放脚本时面临问题

LR 12.50 LR 12.50

OS Windows 7 SP2 操作系统Windows 7 SP2

Protocol is Mobile HTTP/HTML 协议是移动HTTP / HTML

Recording mode is Proxy 记录方式为代理

Let me explain my scenario 让我解释一下我的情况

While executing following function: 执行以下功能时:

  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);

For the above POST method , am getting response as below 对于上述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

Which is fine ,Now the second custom request is shown below 很好,现在第二个自定义请求如下所示

  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);

For the above GET requests in the replay logs am getting: 对于重播日志中的上述GET请求,正在获取:

401 unauthorized error. 401未经授权的错误。

 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"}]}

I refereed this link . 我引用了此链接

My understanding from the above custom request , login is success but the next subsequent requests are getting failed. 从上面的自定义请求,我的理解是登录成功,但是下一个后续请求失败。

I have used web_cleanup_cookies() function but didn't solve the issue . 我使用过web_cleanup_cookies()函数,但没有解决问题。

I tried to capture the Cookie ID using the below function 我尝试使用以下功能捕获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}"));

Now question is where to place parameter "COOKIE_ID" in my script while there is 现在的问题是,在有脚本的情况下将参数“ COOKIE_ID”放在我的脚本中的位置

no value in script for COOKIE_ID? 脚本中没有COOKIE_ID的值?

How to handle this issue ? 如何处理这个问题? Can anybody please help me . 有人能帮我吗?

Please add below headers to the script 请在脚本下方添加以下标题

web_set_sockets_option("SSL_VERSION","TLS");
web_set_user("username", "password", "domain:portno" );
web_set_sockets_option("INITIAL_BASIC_AUTH","1");
  1. In Vugen, Select snapshot view and compare both record and replay requests, suspecting there might be a missing of header in replay request. 在Vugen中,选择快照视图并比较记录请求和重播请求,怀疑重播请求中可能缺少标题。
  2. If cookie is the only thing changing you can add it by using web_add_cookie function. 如果仅更改cookie,则可以使用web_add_cookie函数将其添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM