Web request through proxy server

M

Mike

Does anyone see any problems with this VB .NET code? A customer is using it
and is getting an exception at the line:
myResponse = myRequest.GetResponse()

Private Sub btnTest_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnTest.Click

Dim myRequest As System.Net.WebRequest

Dim myResponse As System.Net.WebResponse

Dim myProxy As New System.Net.WebProxy

Cursor.Current = Cursors.WaitCursor

myRequest = System.Net.WebRequest.Create("http://www.ourserver.com")

myRequest.Timeout = 30000

' Obtain the Proxy Prperty of the Default browser.

myProxy = CType(myRequest.Proxy, System.Net.WebProxy)

If Not myProxy.Address Is Nothing Then

MsgBox("The default Proxy address is: " & myProxy.Address.AbsoluteUri)

End If

Dim newUri As New Uri(txtServer.Text)

' Associate the new Uri object to the myProxy object.

myProxy.Address = newUri

' Create a NetworkCredential object and assign to the Credentials property
of the Proxy object.

myProxy.Credentials = New System.Net.NetworkCredential(txtUser.Text,
txtPassword.Text)

myRequest.Proxy = myProxy

Try

myResponse = myRequest.GetResponse()

MsgBox("Connection worked!")

Catch ex As System.Net.WebException

MsgBox("WebException occurred connecting to server: " & ex.Message)

MsgBox("Exception status = " & ex.Status.ToString)

If Not ex.InnerException Is Nothing Then

MsgBox("InnerException.Message = " & ex.InnerException.Message)

End If

If Not ex.Response Is Nothing Then

MsgBox("Status Code: " & CType(ex.Response,
System.Net.HttpWebResponse).StatusCode)

MsgBox("Status Description: " & ("Status Description: " & CType(ex.Response,
System.Net.HttpWebResponse).StatusDescription))

End If

Catch ex As System.Exception

MsgBox("Unable to connect to server: " & ex.Message)

Finally

Cursor.Current = Cursors.Default

End Try

End Sub
 
M

Mike

I found the problem. There is a bug in the CF:
http://groups.google.com/[email protected]&rnum=5

I read there is a way to specify the Proxy Server for the .NET Framework in
the machine.config file. Does anyone know if the Compact Framework supports
this and also is there a way to also specify a user and password for the
proxy server in machine.config?
 
M

Mike

Putting the Credentials in the WebProxy object works with a proxy server I
downloaded called Proxy+, but it doesn't work with a Raptor Firewall.
Putting the credentials in the WebRequest works with Raptor Firewall, but
you need to put the credentials in the WebProxy object for the "Proxy+"
server. This is with CF 1.0 SP2.

http://www.proxyplus.cz/
I'm using Proxy+ 3.00 (Build #232)

Mike said:
Since that bug was posted in March 2003, I'm wondering if it was fixed in CF
1.0 SP2?
http://groups.google.com/[email protected]&rnum=5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top