Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Web request through proxy server

1 view
Skip to first unread message

Mike

unread,
Feb 20, 2004, 5:16:35 PM2/20/04
to
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


Mike

unread,
Feb 21, 2004, 5:25:05 PM2/21/04
to
I found the problem. There is a bug in the CF:
http://groups.google.com/groups?q=proxy+group:microsoft.public.dotnet.framework.compactframework&hl=en&lr=&ie=UTF-8&oe=UTF-8&group=microsoft.public.dotnet.framework.compactframework&selm=HBfBjcy8CHA.2312%40cpmsftngxa08.phx.gbl&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?


"Mike" <mike...@nospam.msn.com> wrote in message
news:%233uo18$9DHA...@TK2MSFTNGP09.phx.gbl...

Mike

unread,
Feb 25, 2004, 10:48:09 AM2/25/04
to
Since that bug was posted in March 2003, I'm wondering if it was fixed in CF
1.0 SP2?

"Mike" <mike...@nospam.msn.com> wrote in message

news:OXW%23PmM%23DHA...@TK2MSFTNGP09.phx.gbl...

Mike

unread,
Feb 25, 2004, 12:08:23 PM2/25/04
to
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" <mike...@nospam.msn.com> wrote in message

news:%23hPlGb7%23DHA...@TK2MSFTNGP09.phx.gbl...

0 new messages