Highlighted
Trusted Contributor.
Trusted Contributor.
2342 views

HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Hi,

I am using LoadRunner 12.53 Patch 3 version with Web Http protocol to call web services.

Each web service call need a custom header with Session Id, which I am capturing during login (Manula Correlation)

I am using the below code for adding the custom header:

        web_add_header("Sessiontoken", lr_eval_string("{cTest}"));

The response log shows that the session id is sent along with the request.

But I am getting a 400 (Bad Request) error in the response.

If I manually update the session token then the request is working fine.

Error Log Request:

Action.c(118): POST /V31/Security/Logout HTTP/1.1\r\n
Action.c(118): Content-Type: application/json; charset=utf-8\r\n
Action.c(118): User-Agent: ASBMobileConsole/1.0 (iPhone/iPhone5,1; iPhone OS/8.0.1)\r\n
Action.c(118): Sessiontoken: VW4S8FnKiUxihPWai4iZcNyKk9aL3Yd7bCewXJAyzFXdR+vZ8HJY4DvbcR3spu7uURlnmA5SOU1Y
Action.c(118):
eM11LUjiyiYkTor5Y5L3W/Jq5T4oMxkFCeZrc471H5u94bCMMHFruLClEyNk/e5QTmrHhkA2RWH/4oqN4PCv9EiC3X
Action.c(118): IqCa+xAQ6jETa8LK8G7AcHgamt\r\r\n
Action.c(118): Accept-Encoding: gzip\r\n

 

Error Log Output:

Action.c(118): <BODY><h2>Bad Request</h2>\r\n
Action.c(118): <hr><p>HTTP Error 400. The request is badly formed.</p>\r\n
Action.c(118): </BODY></HTML>\r\n
Action.c(118): Error -26631: HTTP Status-Code=400 (Bad Request) for "http://192.168.13.12/V31/Security/Logout" [MsgId: MERR-26631]

0 Likes
1 Solution

Accepted Solutions
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Its working fine now.

I made a mistake with the boundaries 😞

 

View solution in original post

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Could you please share full script with extended log?

 

Thank you!

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Script Snippet:  

  web_reg_save_param_ex(
        "ParamName=cTest",
        "LB=SessionToken: ",
        "RB=\n",
        SEARCH_FILTERS,
        LAST);
    
    web_reg_save_param("cSessionId1","LB=SessionToken: ", "RB=\n", LAST);
    
    lr_start_transaction("Mobile_Services_01_Login");
    
        web_add_header("AppD_Header", "Mobile_Services_01_Login");
        
        web_add_header("Field1", lr_eval_string("{pField1}"));
        
        web_add_header("User-Agent", lr_eval_string("{pUser-Agent}"));

        web_custom_request("Login2",
            "URL={pServerURL}/{pMobileVersion}/Security/Login2", 
            "Method=POST", 
            "Resource=0", 
            "RecContentType=application/json", 
            "Referer=", 
            "Snapshot=t1.inf", 
            "Mode=HTML", 
            "EncType=application/json; charset=utf-8", 
            "Body={pMessageId}",            
             LAST);       

 

  web_add_header("User-Agent", lr_eval_string("{pbrUser-Agent}"));
        
        web_add_header("Sessiontoken", lr_eval_string("{cTest}"));
                
        web_custom_request("Logout", 
            "URL={pServerURL}/{pMobileVersion}/Security/Logout", 
            "Method=POST", 
            "Resource=0", 
            "RecContentType=application/json", 
            "Referer=", 
            "Snapshot=t16.inf", 
            "Mode=HTML", 
            "EncType=application/json; charset=utf-8", 
            "Body={}",
            LAST);

 

Extended Log:

Action.c(118): t=4318ms: 464-byte request headers for "http://192.168.13.12/V31/Security/Logout" (RelFrameId=1, Internal ID=3)
Action.c(118): POST /V31/Security/Logout HTTP/1.1\r\n
Action.c(118): Content-Type: application/json; charset=utf-8\r\n
Action.c(118): User-Agent: ASBMobileConsole/1.0 (iPhone/iPhone5,1; iPhone OS/8.0.1)\r\n
Action.c(118): Sessiontoken: VW4S8FnKiUxihPWai4iZcNyKk9aL3Yd7bCewXJAyzFXdR+vZ8HJY4DvbcR3spu7uURlnmA5SOU1Y
Action.c(118): eM11LUjiyiYkTor5Y5L3W/Jq5T4oMxkFCeZrc471H5u94bCMMHFruLClEyNk/e5QTmrHhkA2RWH/4oqN4PCv9EiC3X
Action.c(118): IqCa+xAQ6jETa8LK8G7AcHgamt\r\r\n
Action.c(118): Accept-Encoding: gzip\r\n
Action.c(118): Accept: */*\r\n
Action.c(118): Connection: Keep-Alive\r\n
Action.c(118): Host: 192.168.13.12\r\n
Action.c(118): Content-Length: 2\r\n
Action.c(118): \r\n
Action.c(118): t=4320ms: 2-byte request body for "http://192.168.13.12/V31/Security/Logout" (RelFrameId=1, Internal ID=3)
Action.c(118): {}
Action.c(118): t=4322ms: 179-byte response headers for "http://192.168.13.12/V31/Security/Logout" (RelFrameId=1, Internal ID=3)
Action.c(118): HTTP/1.1 400 Bad Request\r\n
Action.c(118): Content-Type: text/html; charset=us-ascii\r\n
Action.c(118): Server: Microsoft-HTTPAPI/2.0\r\n
Action.c(118): Date: Thu, 02 Feb 2017 01:55:45 GMT\r\n
Action.c(118): Connection: close\r\n
Action.c(118): Content-Length: 311\r\n
Action.c(118): \r\n
Action.c(118): t=4339ms: 311-byte response body for "http://192.168.13.12/V31/Security/Logout" (RelFrameId=1, Internal ID=3)
Action.c(118): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">\r
Action.c(118): \n
Action.c(118): <HTML><HEAD><TITLE>Bad Request</TITLE>\r\n
Action.c(118): <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>\r\n
Action.c(118): <BODY><h2>Bad Request</h2>\r\n
Action.c(118): <hr><p>HTTP Error 400. The request is badly formed.</p>\r\n
Action.c(118): </BODY></HTML>\r\n
Action.c(118): Error -26631: HTTP Status-Code=400 (Bad Request) for "http://192.168.13.12/V31/Security/Logout" [MsgId: MERR-26631]

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Hi,

Is it possible to share full script zip file?

Thank you!

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Its working fine now.

I made a mistake with the boundaries 😞

 

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: HTTP Status-Code=400 (Bad Request) when adding my session id in the header

Jump to solution

Great!

Thanks!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.