从程序调用网页

本文关键字:网页 调用 程序 | 更新日期: 2023-09-27 18:28:18

我希望我的c#程序在打开网页时调用它。网页中的代码将增加一个计数器。。。因此我只需要程序来调用页面。不要认为我需要发布或获取或其他任何东西。

想法?

从程序调用网页

有关更多信息,请查看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 ();

如果你不能从上面提取你需要的代码。。这是

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

我知道这已经很晚了,但对于未来可能会陷入这种境地的人来说。

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