Reputation: 23295
How does the following code need to be modified to send the WebRequest
via a specified proxy server
and 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
Upvotes: 3
Views: 23545
Reputation: 772
For example, if your Web server needs to go through the proxy server at 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
Upvotes: 0
Reputation: 270
use this code from MSDN :
Dim myProxy As New WebProxy()
myProxy.Address = New Uri("proxyAddress")
myProxy.Credentials = New NetworkCredential("username", "password")
myWebRequest.Proxy = myProxy
Upvotes: 7
Reputation: 2322
A WebRequest object has a 'Proxy' property of IWebProxy. You should be able to assign it to use a specified proxy.
Request.Proxy = New WebProxy("http://myproxy.com:8080");
If the proxy is not anonymous, you will need to specify the Credentials of the WebProxy object.
Upvotes: 4