proxy経由の通信


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

未実行

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