views:

79

answers:

4

I m trying to invoke a URL in C#, I am just interested in invoking, and dont care about response. When i have the following, does it mean that I m invoking the URL?

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+2  A: 

No when you say request.GetResponse(); then you invoke it.

Vinay Pandey
+4  A: 

You need to actually perform the request:

var request = (HttpWebRequest)WebRequest.Create(url);
request.GetResponse();

The call to GetResponse makes the outbound call to the server. You can discard the response if you don't care about it.

John Källén
You should, however, close the response after that to avoid keeping the connection/download open.
Lucero
+1  A: 

Probably not. See: http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

You're allowed to set the Method, ContentType, etc., all which would have to be done before the request is actually sent. It looks like GetResponse() actually sends the request. You can simply ignore the return value.

Nelson
+1  A: 

Hi,

You can use this :

string address = "http://www.yoursite.com/page.aspx";
using (WebClient client = new WebClient())
{
   client.DownloadString(address);
}
Xstahef