Click here to Skip to main content
Rate this: bad
good
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 11:31am
Edited 21-Nov-12 11:34am
v2

1 solution

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

Solution 1

  Permalink  
Comments
CrispMuffin at 21-Nov-12 17:50pm
   
I'm still very new to this, how do i get a string of a WebResponse?
wizardzz at 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 at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
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