views:

59

answers:

1

I have sent many http requests in cycle with

WebRequest request = (WebRequest)WebRequest.Create(str);

This line takes about 500ms on my computer

WebResponse response = request.GetResponse(); 

On other computers on the network: 10-20ms

how to fix this bug? What reasons could there be for other computers on the network completing their request faster?

There is no proxy installed, and the request is to 127.0.0.1:port.

code for log

String IdHTTPUt_Get(string str) { string res="";

DateTime dt = DateTime.Now;

WriteLog("begin");

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

WebRequest request = (WebRequest)WebRequest.Create(str);

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

request.Credentials = new NetworkCredential(opt_Utor_User,opt_Utor_Password);

request.Method = "GET";

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

request.Proxy = null;

using (WebResponse response = request.GetResponse())

{

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

Stream receiveStream = response.GetResponseStream();

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

StreamReader readStream = new

StreamReader(receiveStream,Encoding.UTF8);

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

res = readStream.ReadToEnd();

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

receiveStream.Close();

readStream.Close();

}

WriteLog((DateTime.Now - dt).ToString()); dt = DateTime.Now;

return res;

}

A: 

Which line is taking the time - WebRequest.Create or request.GetResponse()?

Are you disposing of the response at the end? It should be within a using statement:

using (WebResponse response = request.GetResponse())
{
    ...
}

The connection pool limits the number of connections you can make to any particular host - in this case you would end up waiting for the garbage collector to release an earlier response. That may not be the problem, but I wouldn't be surprised to find it was.

EDIT: Of course, the other possibility is that it's just taking a long time to process the request on your machine. What is the request doing? If you make the same request from other machines (but still to your machine) how long does that take?

Jon Skeet
begin00:00:00.005000300:00:0000:00:0000:00:00.527030100:00:0000:00:0000:00:0000:00:00
AlexGu
(WebResponse response = request.GetResponse() takes 527ms
AlexGu
from other mashine to local( utorrent web api ) adn to remote mashine work fine.some bug in IE ( is request processed with IE?)..
AlexGu
@AlexGu: No, it's not processed with IE. That's extremely strange...
Jon Skeet