Problems with NetworkCredientials in HttpWebRequest

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
 
V

Vadym Stetsyak

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top