HttpWebRequest-Timeout

HttpWebRequest-Timeout


You can set time to live on for connection to the server using HttpWebRequest object Timeout property
as shown in below code.

using  System.Net;

 protected void Button1_Click(object sender, EventArgs e)
{

   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(http://opi.yahoo.com/online?u=my_yahooid&m=s&t=8); 

  // setting up connection with web and posting

  request.Timeout = 15 * 1000;  

  // This is timout in millisecond 1 second = 1000 milliseconds 
 
  request.ContentType = "application/x-www-form-urlencoded";  

//   you can set content type of request to  application/x-www-form-urlencoded 

  HttpWebResponse response = (HttpWebResponse)request.GetResponse();


// Returns httpwebresponse StreamReader reader = new StreamReader(response.GetResponseStream());

Response.Write(reader.ReadToEnd());

}

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Author

code tutorial