3

如何修改以下代码以WebRequest通过指定的proxy serverand发送port number

Dim Request As HttpWebRequest = WebRequest.Create(url)
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Using writer As StreamWriter = New StreamWriter(Request.GetRequestStream())
    writer.Write(params)
End Using
4

3 回答 3

7

使用 MSDN 中的此代码:

Dim myProxy As New WebProxy()
myProxy.Address = New Uri("proxyAddress")
myProxy.Credentials = New NetworkCredential("username", "password")
myWebRequest.Proxy = myProxy
于 2012-11-19T06:06:33.213 回答
4

WebRequest 对象具有 IWebProxy 的“代理”属性。您应该能够将其分配给使用指定的代理。

Request.Proxy = New WebProxy("http://myproxy.com:8080");

如果代理不是匿名的,您将需要指定 WebProxy 对象的凭据。

于 2012-11-19T04:17:53.250 回答
0

例如,如果您的 Web 服务器需要通过代理服务器http://255.255.1.1:8080

Dim Request As HttpWebRequest = WebRequest.Create(url)
 'Create the proxy class instance
Dim prxy as New WebProxy("http://255.255.1.1:8080")

 'Specify that the HttpWebRequest should use the proxy server
Request .Proxy = prxy

Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Using writer As StreamWriter = New StreamWriter(Request.GetRequestStream())
writer.Write(params)
End Using
于 2012-11-19T06:38:56.010 回答