Problems with NetworkCredientials in HttpWebRequest

  • Thread starter Thread starter mroffey
  • Start date Start date
M

mroffey

Hi I'm using the code below to post to a web form, but when I run it, i
get System.Net.WebException: The operation has timed-out.
error

Obviously something is wrong, can anyone give me a clue?

string url = "http://localhost/testapp/test.asp";
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Credentials = new NetworkCredential("username",
"password", null);
myHttpWebRequest.Method = "POST";
try
{
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
}

catch (Exception e)
{
Response.Write (e.ToString();)

}

The error I get is
System.Net.WebException: The operation has timed-out. at
System.Net.HttpWebRequest.GetResponse()

I've set the test.asp file to write out a text file if it receives a
POST request. Its getting nothing.



Thanks in advance for any help you can give.
Mark
 
Why do you think that the trouble is with credentials?
AFAIK if credentials weren't okay then server would respond with 401 or 403
error.

Since, you get timeout, something is wrong with the network or server code
that is processing code.

Just a hint: do setup connection limit for ServicePoint?

By default maximum is set to 2 connections. That is if you have 2
connections and then issue request.GetResponse() - it is quite possible that
you'll receive timeout.

To increase maximum connection limit by 15 use following code
HttpWebRequest request;
//some code here
request.ServicePoint.ConnectionLimit = 15;
 
Back
Top