0

Web ページが開いたときに C# プログラムで Web ページを呼び出すようにしたいと考えています。Webページのコードはカウンターをインクリメントします...したがって、プログラムでページを呼び出すだけで済みます。投稿したり、取得したりする必要があるとは思わないでください。

考え?

4

2 に答える 2

1

詳細については、 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 ();
于 2013-08-18T21:18:46.457 に答える
0

私はそれが遅いことを知っていますが、これに陥る可能性のある将来の人々のために.

System.Net.WebClient client = new System.Net.WebClient();
client.DownloadDataAsync(new Uri("http://stackoverflow.com"));
于 2014-03-28T14:17:43.377 に答える