Click here to Skip to main content
12,690,140 members (31,080 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
I have a code that connects to a php page to check a version, but its always so slow on the first time.
After that it gets the content instantly, anyone know why?

I use:
try
            {
                WebRequest req = WebRequest.Create(URI);
                WebResponse resp = req.GetResponse();
                StreamReader sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
Posted 21-Nov-12 12:31pm
Updated 21-Nov-12 12:34pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
CrispMuffin 21-Nov-12 17:50pm
   
I'm still very new to this, how do i get a string of a WebResponse?
wizardzz 21-Nov-12 17:58pm
   
You are using a webresponse, and reading it into a StreamReader from a Stream. Calling readtoend() on the StreamReader is returning a string.

You are doing that in these 3 lines of code:
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
CrispMuffin 21-Nov-12 18:08pm
   
I got it to work, but it's the same speed, any other things?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100