0

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?

Sheldon
  • 57
  • 1
  • 3
  • 4

2 Answers2

1

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 ();
CaldasGSM
  • 3,032
  • 16
  • 26
  • Essentially the webpage is www.mywebsite.com/counter.php?theID I don't care about how reliable the process is. counter.php will take theID and do stuff with it... I don't need to pass along credentials or anything. – Sheldon Aug 19 '13 at 07:08
0

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"));
Tony
  • 1,297
  • 10
  • 17
  • I am curious why this was down voted? I will gladly delete it if there is a valid reason. – Tony Jan 03 '16 at 04:30