Last post Dec 10, 2009 03:36 AM by rajivharris
Dec 02, 2009 05:07 AM|rajivharris|LINK
I am trying to access a website using httpwebrequest.
It is getting me response when Fiddler is turned on. But throws 401 unauthorized excpetion when Fiddler is not running.
Appreciate your help in this regard.
PFB my code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sWebAddress);
request.Credentials = new NetworkCredential("username", "pwd", "domain");
CookieContainer cookieJar = new CookieContainer();
request.CookieContainer = cookieJar;
request.Accept = "*/*";
request.KeepAlive = true;
// Get the response.
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
responseFromServer = reader.ReadToEnd();
// Clean up the streams.
401 Unauthorized Error
Dec 02, 2009 07:34 AM|satalaj|LINK
HttpWebRequest has nothing to do with client side browser.
Try it in another browser.
Dec 02, 2009 07:56 AM|rajivharris|LINK
Am not trying it in browser. I am using HttpWebrequest in my app to access a website.
It is working fine when I have fiddler on. Otherwise getting the exception "Unathourized".
Dec 02, 2009 08:35 AM|satalaj|LINK
As per my knowledge Fiddler is client side plugin for browser.
Can you tell me what exactly the fiddler is doing for you at server side ?
Dec 03, 2009 09:16 AM|rajivharris|LINK
I found that Keep-Alive is not going in header when it is redirected.
I have set "request.KeepAlive = true;" but still it is going in header.
I am using .net 2.0 f/w.
Dec 03, 2009 10:08 AM|satalaj|LINK
Can you try to set
request.ContentType = "application/x-www-form-urlencoded";
What is the use of fiddler in your scenario ?
Dec 10, 2009 03:36 AM|rajivharris|LINK
It is not working.