3

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

3 Answers 3

7

use this code from MSDN :

Dim myProxy As New WebProxy()
myProxy.Address = New Uri("proxyAddress")
myProxy.Credentials = New NetworkCredential("username", "password")
myWebRequest.Proxy = myProxy
Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.