Page 1 of 1

is there a way to get URL if it requires you to be logged in

Posted: Thu Sep 11, 2008 9:21 pm
by Paul D
the page im trying to view requires you to be logged in. i keep the cookies on my computer to stay logged in without having to enter my username and pw... if i open firefox i can see the page, but URL in rev returns the websites default about not being logged in... does revolution have URL cookie support or is there a way to tell the URL command to tell the link im trying to get that i have the required info to view the page?

Posted: Thu Sep 11, 2008 9:54 pm
by Janschenkel
Check out the 'libUrlSetCustomHttpHeaders' command and 'libUrlLastRHttpHeaders' function in the Revolution dictionary. You'll have to examine the cookies information and set that as part of your custom HTTP headers before calling 'get url' or 'post to url'.

Hope this gets you closer to a solution,

Jan Schenkel.

Posted: Fri Sep 12, 2008 3:51 pm
by trevordevore
Cookies are sent/received from the server using the header so you can mimic what your browser does using Revolution. To begin with you need to send your username and password to the server. How you do this depends on the authentication scheme your server uses. If you need help with that let us know.

After you have sent a valid username/password to the server the server replies with a header that contains the cookie data. As Jan said you can get at those headers using libURLLastRHHeaders().

You need to look through the returned headers for a "Set-Cookie:" entry. Once you find that you can extract the name/value pairs. Using those name/value pairs you construct a "Cookie:" entry in the header that you will send back to the server with each request.

I find it is easiest to use the 'httpheaders' property when working with cookies. libURL will add (or replace libURL default values) any headers defined in 'httpheaders' when sending your request. If you use libUrlSetCustomHttpHeaders you have to rewrite the entire header yourself.

So after extracting the cookie information from the server's respone header and creating your "Cookie: name/value;name/value" string you can set the 'httpheaders' before sending your next request to the server:

set the httpHeaders to "Cookie: name/value;name/value"

libURL will add the value to the header list and the server should accept your request. Note that you may need to pay attention to the expiration date of the cookie that the server returns. The following article explains the format of Set-Cookie and Cookie and may prove useful:

http://www.codeguru.com/cpp/i-n/isapi/c ... .php/c4493

Posted: Mon Sep 15, 2008 4:17 pm
by Paul D
good enough, ill start taking a crack at what im trying to do... thanks for the help!

Posted: Thu Nov 06, 2008 4:59 pm
by SparkOut
I'm facing a similar task, and I'd like to know if it's possible to force a POST to follow a redirect from the server?
I am trying to create a log in to automate collection of survey response data for a client which is held on their web server and stored in a file - easy enough except the login is an aspx page which redirects after submission.
I can post the username and password OK, and I get the 200 OK returned, but I don't get a redirect to the success page which passes the cookies. I can use LiveHTTPHeaders in Firefox to see the cookies being set, but I can't access them via libUrlLastRHHeaders in Rev.
Any way of forcing a redirect using POST? (for that matter, I can't seem to make libUrlFollowHTTPRedirects work with GET methods either, but that's not the real issue I need to address at the moment).

Posted: Fri Nov 14, 2008 4:27 am
by trevordevore
libURL does not try to follow redirects unless it is a GET request. You could try modifying libURL yourself.

You can open the script for libURL by executing the following in the message box:

Code: Select all

edit the script of button "revlibURL" of stack "revLibrary"
Search for this line of code:

Code: Select all

case laStatusCode[laUrl[x]] is among the items of "301,302,307" and laAction[laUrl[x]] is "getdata" and lvFollowHttpRedirects is not false
Replace it with this line of code (yes, you should make a backup):

Code: Select all

case laStatusCode[laUrl[x]] is among the items of "301,302,307" and laAction[laUrl[x]] is among the items of "getdata,postdata" and lvFollowHttpRedirects is not false
libURL should now try to follow redirects when making a POST request.

Posted: Fri Nov 14, 2008 10:48 am
by SparkOut
That's brilliant Trevor, thanks!

(Mind you, I still can't make it work - there's something funny about the way this stupid aspx page handles the login, I still can't see the cookies being set in the headers returned).

Posted: Fri Nov 14, 2008 4:50 pm
by trevordevore
Are you relying on libUrlLastRHHeaders or are you watching all sent/received headers using libURLSetLogField? If you aren't using libURLSetLogField I would try that and see if you see the cookies. Perhaps libUrlLastRHHeaders doesn't contain the right data after a redirect?

Posted: Fri Nov 14, 2008 11:27 pm
by SparkOut
I'm using both, Trevor. Everything is logged in the log field, but it shows the same stuff as the libUrlLastRHHeaders.
It doesn't matter too much, as I've used revBrowser to build a login and then collect the htmlText for the page in question, but I'd dearly wish to just collect the cookies from the login page and pull the data in without that.

Posted: Tue Nov 18, 2008 2:44 pm
by SparkOut
Thanks for the above, Trevor, I have finally got it working to follow the redirect after POST, that's brilliant.
(I needed to GET the page first without following redirects, to interrogate some viewstate parameters which changed on login, and only then POST the login data, which was why it wasn't following the redirect before.)

Now I have a system where I can step through the code in the debugger and see the headers being returned, extract the session cookies and set them in the headers before getting the data page. All seems great - until I clear the breakpoints and let the code run unhindered. As soon as I do that, the log field and data remain blank and there seems to be no response from the IDE, although it doesn't lock (well, not every time).

I've got resetAll and and unloadAll handlers to clear the cache (not that there is one for the type of operation I'm doing - not using "load") at the top of the script. Any thoughts why it should work when stepping through but not otherwise? It doesn't seem to be just timing lag, as I've put wait loops and answer dialogs in the script at various places.

Posted: Tue Nov 18, 2008 4:36 pm
by SparkOut
I seem to have answered my own question - removing the "resetAll" (which I only did to try and fix the issue of repeat test runs) has cured it completely. :roll: This despite having delays and answer dialogs in between the script starting and the first url operation. :?:

Posted: Fri Nov 21, 2008 2:30 am
by trevordevore
A little note about the change to libURL I posted. I've been reading the HTTP specs and there is some specific behavior that is expected for 3xx responses when using POST requests.

301, 302 and 307: Only automatically redirect if the request is GET or HEAD. DO NOT automatically redirect for anything else. Prompt the user.

303: The redirect url should be retrieved using a GET method.

A note in the specs suggests that many clients treat 302 as if it were a 303.

The code I posted doesn't take these conditions into account. It just retrieves the URL using GET.

I think libURL should be updated with a callback if a 301, 302 or 307 is returned in which the developer could specify whether or not to repost to the new url, use GET or do nothing. For 303 libURL should automatically fetch the new url using GET.