Forum Discussion

baba_k's avatar
baba_k
Occasional Contributor
13 years ago

How to update the URL in request header through OnLoadReuest event handler

Hi...

Can anyone please let me know, how to update the URL in get request header through event handler.

I am able to retreive the (below specified) request header using onloadrequest.



I have to update the  GET /xyz/abc.aspx HTTP/1.1

 to GET /123/345.aspx HTTP/1.1



I do not want to save this in a txt file and replace. 

PLease help  on how to replace this and pass the updated value instead of old value in the request

Request Header:


GET /xyz/abc.aspx HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us
Cache-Control: no-cache
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=fffbtg55l1b1a245cgnrlymb; HttpOnly; .ASPXAUTH=8432932D13AF6D34CDF4121E65F94E57B603A57582ACDC65C6D04DFA4E2670AA1311A365C67899B81A2C34C23B5C37E2FA9648FD992DE941C5D410B6715C10F2453FE079CB85FF792262D021ABC4BCE1D92C80BFEFE72B35E09B62A3F1E7AB48B5E1C4D330D79DF3ADC09D86599EA8B7F06BA16C68D9587674010E151F2367A3EBD179AA; HttpOnly; HttpOnly
Host: XYZ:80
Referer: http://xyz/
UA-CPU: x86
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)


 


 

5 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Baba,



    First of all, may I ask you what you would need to do this at run time for? If you need this to update the originally recorded task, you can manually replace the request URL in the Task editor before the test run. Or, you can delete the old request and record a new one in its place (append recording to the existing task, then move the new request to the needed place in the task). That would be easier and with no overhead to the test performance, whereas, load testing event handlers may slow down the test execution.



    If you are sure that you want to stick with run-time modification, you'll need to perform a string replace in the Request.RequestHeader value within the OnLoadTestingRequest event handler, and replace the original URL with the needed URL. Here's an example:

    Sub GeneralEvents_OnLoadTestingRequest(Sender, User, Request)

      ' Replace 42 in the below condition with the request # in the task

      If Request.RequestID = 42 Then

        Request.RequestHeader = aqString.Replace(Request.RequestHeader, "/xyz/abc.aspx", "/123/345.aspx")

      End If

    End Sub


    By the way, have you seen our new load testing tool - LoadComplete? Version 2 is currently in beta with many major improvements. Would you possibly be interested to try it out?
  • baba_k's avatar
    baba_k
    Occasional Contributor
    Hi Helen,

    the reason for asking to replae th URL is that there are dymanic values in url that are to be replaced, the problem is that this dynamic value is not in any variable.

    The url will look something like



    GET ABC.aspx?wuiebgiwebnghejkbnjkNHNHWNH html1.1



    As you can see that there is no variable mentioned after the ?

    I need to replace this value (wuiebgiwebnghejkbnjkNHNHWNH) with newly captured variable.

    I tried doing this by using url varialbes but it failed as the replaced url displayed something like



    GET ABC.aspx?wuiebgiwebnghejkbnjkNHNHWNH=wiojgowgognowengownbho html 1.1 where wiojgowgognowengownbho is the new value.

    the string replace that you have suggested is also not working. it is still displaying the old value after doing a string replace.



    Let me know if you have any thoughts about this.


  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Baba,



    the string replace that you have suggested is also not working. it is still displaying the old value after doing a string replace.


    If you mean that the old value is still displayed in the Task editor, this is normal. Any changes made at run time are preserved only during the test run and not applied to the original recorded requests. The load test log, though, will display the actual URL in the Headers panel.



    If the URL isn't actually getting updated, I suggest that you debug the event handler to see why this could happen. That is, set a breakpoint inside the event handler and when the test is paused, inspect the Request parameter in the Locals panel before and after the replace operation.



    It is also possible that you need to use case-insensitive replace because aqString.Replace is case-sensitive by default. To do this, add False as the last parameter of the method call:



    Try that and let me know the results.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Ravi,


     


    Helen has posted many suggestions on how to resolve the issue. Which ones did you try, and why didn't they work?