Sheldon
Sheldon

Reputation: 57

Call webpage from program

I would like my c# program to call a webpage when it opens. The code in the webpage will increment a counter... thus I just need the program to call the page. Don't think that I need to post or get or anything else.

Thoughts?

Upvotes: 0

Views: 3073

Answers (2)

Tony
Tony

Reputation: 1307

I know its late but for future people who might fall onto this.

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadDataAsync(new Uri("http://stackoverflow.com"));

Upvotes: 0

CaldasGSM
CaldasGSM

Reputation: 3062

for more information check out msdn

// Create a request for the URL. 
WebRequest request = WebRequest.Create (
"http://www.contoso.com/default.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams and the response.
reader.Close ();
response.Close ();

if you can't extract the code you need from the above.. here it is

WebRequest request = WebRequest.Create ("http://www.mysite.com/counter.php?YourId");
WebResponse response = request.GetResponse();
response.Close ();

Upvotes: 1

Related Questions