views:

438

answers:

2

Guys,

I am trying to create a script that logins to a webpage and grabs a report - all is working GREAT except - I am getting a

HTTP/1.1 302 MovedTemporarily
Date: Mon, 22 Jun 2009 13:22:04 GMT
Server: Server
x-some-id-1: 0J3X3VBBCGNJG9V46G5D
x-some-id-2: BtQ4SsDhbryWgiVNFcVpMbt898GuPIBaWuGwAWjvsyI=
Set-cookie: session-id-time=1246258800l; path=/; domain=.example.com; expires=Mon Jun 29 07:00:00 2009 GMT
Set-cookie: session-id=179-5933843-4704124; path=/; domain=. example.com; expires=Mon Jun 29 07:00:00 2009 GMT
Location: https://example.com
Vary: Accept-Encoding,User-Agent
nnCoection: close
Content-Type: text/html; charset=UTF-8
Content-Length: 0

Response and I have no idea how to stop it. I have tried settings the

httpwebrequest.allowautoredirect both "True" and "False" and nothing helps.

It's trying me crazy as I can login to the website via https:// but then I get this returned?

+1  A: 

I was stuck on this problem for a long time - so glad I can help. Read this article

http://www.byteblocks.com/page/How-to-submit-requests-to-web-sites-programatically-using-HttpWebRequest.aspx

The key issue is that you cannot use HttpWebRequest with automatic redirects enabled to do a login process involving 302s and cookies because the cookies don't get set until the end of the whole process.

The solution is to disable auto redirects and implement the whole login process manually on a step-by-step basis (get the 'Location' header of 302 redirect responses, as well as the 'Set-cookie' header, and pass these down to successive steps as needed).

Your cookie container needs to grab all the cookies along the way and submit them at the end. If you are getting a 302 - you will be hitting your head against the wall wondering why you keep ending up at the login page.

+1  A: 

Also check this page - may help

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic55864.aspx