.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > Unable to get response from a peculiar website: 401 Error, It authenticates twice.
 

Unable to get response from a peculiar website: 401 Error, It authenticates twice.

Hi,

We connect to an external website via https to learn about the files we have to download. Here we have to parse the html, etc, etc, to know what to download. Something weird I've noticed is that we have to provide our credentials twice to download that page (i.e. get its html). How can u mimic is nature of authentication using the HttpWebRequest & HttpWebResponse objects?

EDIT: Since I can't post the entire code here is a gist of what I've done so far...
Usually our systems are connected to the internet via a proxy. So the first bit of code deals with giving proper proxy authentication. Next I define a CredentialCache object, and add the two credentials. Both have the same uri, but the key (authtype) is different. I have to give a different key-name since the uris are the same. Why r the uris same? Well, I noticed that from the website; the popup which asks for authentication asks for this...
I am a bundle of mistakes intertwined together with good intentions
  • Edited bydeostroll Tuesday, September 08, 2009 12:27 AMadded more info
  •  
deostroll
Does your proxy require authentication? For eg, if you used a browser to browse to an external website, would you have to authenticate through the proxy first?

The best way to figure out what is happening, is to install a browser extension that can sniff the HTTP requests. I use Firebug in Firefox. Enable firebug extension, then go through your scenario. In the Net tab of firebug, it will show you the requests being sent. Try to emulate the same requests in your code.

hope this helps.
feroze
--
My blog
Feroze Daud
Is there a way I can compare what my application is communicating vs what my browser is communicating?
I am a bundle of mistakes intertwined together with good intentions
deostroll
Sure.

One way is to install wireshark. Then, do a network sniff of bothh your app and your browser, and compare them side by side.

Or, you can use Firebug to get the browser requests. Then, use system.net logging http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html to see the httpwebrequest session. And then compare them both.
feroze
--
My blog
Feroze Daud
Yes, I have wireshark. But is it possible to concentrate on that particular website and capture traffic?

I am a bundle of mistakes intertwined together with good intentions
deostroll

You can use google to search for other answers

Custom Search

More Threads

• An established connection was aborted by the software in your host machine
• Working w/ NetworkStream - Windows XP freak bug?
• process/application using internet connection
• Copying files over network
• Problems with NTLM proxy authentication and HTTPS
• DNS - Host Not Found
• How can I use cookies stored by Internet Explorer 7(in Vista) in my WinForms application?
• How to specify notification (bounce) mails reciever
• how to download Large file (min 200 MB) in asp.net
• How to replace "address from" in SMTP .NET with another email address