proxy経由の通信

「proxy経由の通信」の編集履歴(バックアップ)一覧に戻る

proxy経由の通信 - (2015/04/09 (木) 00:54:38) のソース

未実行

 WebRequest myWebRequest = WebRequest.Create("http://targetaddress.com");
 
 WebProxy myProxy = new WebProxy();
 // Obtain the Proxy Prperty of the  Default browser.  
 myProxy = (WebProxy)myWebRequest.Proxy;
 
 // Create a new Uri object.
 Uri newUri = new Uri("http://proxyaddress.com:8080");
 
 // Associate the new Uri object to the myProxy object.
 myProxy.Address = newUri;
 
 // Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
 myProxy.Credentials = new NetworkCredential(username,password);
 myWebRequest.Proxy = myProxy;
 
 WebResponse myWebResponse = myWebRequest.GetResponse();
 
 Stream streamResponse=myWebResponse.GetResponseStream();
 StreamReader streamRead = new StreamReader( streamResponse );
 Char[] readBuff = new Char[256];
 int count = streamRead.Read( readBuff, 0, 256 );
 Console.WriteLine("\nThe contents of the Html pages are :");	
 while (count > 0) 
 {
     String outputData = new String(readBuff, 0, count);
     Console.Write(outputData);
     count = streamRead.Read(readBuff, 0, 256);
 }
 
 // Close the Stream object.
 streamResponse.Close();
 streamRead.Close();
 
 // Release the HttpWebResponse Resource.
 myWebResponse.Close();

2015/04/08