如何通过指定的WebRequest
和proxy server
修改以下代码以发送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
答案 0 :(得分:7)
使用MSDN中的代码:
Dim myProxy As New WebProxy()
myProxy.Address = New Uri("proxyAddress")
myProxy.Credentials = New NetworkCredential("username", "password")
myWebRequest.Proxy = myProxy
答案 1 :(得分:4)
WebRequest对象具有IWebProxy的“Proxy”属性。您应该能够将其分配为使用指定的代理。
Request.Proxy = New WebProxy("http://myproxy.com:8080");
如果代理不是匿名的,则需要指定WebProxy对象的凭据。
答案 2 :(得分: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