How to capture the URL that is formed because of redirection?

How to capture the URL that is formed because of redirection?

Example:

When visiting http://www.mercury.com, user will be redirected to a different location. How to capture the redirected URL.

Solution

Use web_reg_save_param()

When that the server redirects a HTTP request to another URL, it normally does that by sending a HTTP 302 Moved header. To verify

1. Run the script in extended log with "data retuned by server’ turned on

2. Check the execution log for "302 moved’

You can also see that along with this header, the server also sends the following header information:

"Location: <URL>."

The URL specified in the "Location’ header will be the URL that the original HTTP request be redirected to. To capture this URL, you have to capture the string between "Location:" and "\r\n" (end of line).

Example:

Action()

{

//use the correlation statement to capture the redirection

web_reg_save_param ("Redirection", "LB=Location: ","RB=\r\n" ,LAST );

//Visit Mercury homepage

web_url("Mercury","URL=http://www.mercury.com/", LAST);

//Print the redirected URL

lr_message("redirected address = %s", lr_eval_string("{Redirection}"));

return 0;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s