c# - Ways of speeding up WebRequests? -


this question has answer here:

i've made app can access , control onvif cameras enough. first time making app uses web requests (or @ all) assume i'm using quite basic techniques. part of code i'm curious this:

        uri uri = new uri(             string.format("http://" + ipaddr + "/onvif/" + "{0}", service));          webrequest request = webrequest.create((uri));         request.method = "post";          byte[] b = encoding.ascii.getbytes(postdata);         request.contentlength = b.length;         //request.timeout = 1000;         stream stream = request.getrequeststream();         //send message         xmldocument recdata = new xmldocument();         try         {             using (stream = request.getrequeststream())             {                 stream.write(b, 0, b.length);             }             //store response             var response = (httpwebresponse) request.getresponse();             if (response.getresponsestream() != null)             {                 string responsestring = new                   streamreader(response.getresponsestream())                   .readtoend();                 recdata.loadxml(responsestring);             }         }         catch (systemexception e)         {             messagebox.show(e.message);         }         return recdata;     } 

the code works fine, using writeline statements i've found first request takes 400ms complete whereas subsequent ones take between 10 - 20ms. there can speed first request?

you're doing fine. reason difference in time complete may due http keep-alive. default, same connection reused subsequent requests. first request has establish connection, why takes longer. rest of requests use same already-open connection.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -