401 error from proxy server

M

Mike

Using the .NET Compact Framework on a Pocket PC 2003, I am attempting to
access a web page on the internet through a proxy server. I'm setting the
proxy server name, port, username, and password in my VB .NET code:

myRequest = System.Net.WebRequest.Create(RsURL)

myRequest.Timeout = 30000

myProxy = New System.Net.WebProxy

myUri = New Uri(Utils.GetOption(cmd, "ProxyServer"))

' Associate the new Uri object to the myProxy object.

myProxy.Address = myUri

sProxyUser = Utils.GetOption(cmd, "ProxyUser")

myProxy.Credentials = New System.Net.NetworkCredential(sProxyUser,
Utils.GetOption(cmd, "ProxyPwd"))

myRequest.Proxy = myProxy

myResponse = myRequest.GetResponse()

An exception is raised with the Message = "The remote server returned an
error: (401) Unauthorized" on the GetResponse() call. The request doesn't
appear to be making it to
the final destination - the request doesn't show up in our web log. So the
response must be coming from the proxy server. It's supposed to be a
"Raptor Firewall". Pocket Internet Explorer is able to access web pages
through it.

What's the best way to fix this problem?

(I'm posting to this newsgroup because it's the closest one that is
monitored by the MSDN Managed Newsgroups feature)
 
R

Roger Willcocks

Looks 'OK' but you might try using Basic Auth instead of network
credentials
Also didn't see a domain in the code.
 
M

Mike

How would I do "Basic Auth"? With a CredentialCache? If I use a
CredentialCache, what do I specify for the uriPrefix argument for the Add
method?

The IT guy at the client side has said that Pocket Internet Explorer
connects without prompting if you put the username and password in the
"Socks 5 Login" settings in the Pocket PC. So apparently it doesn't need a
domain? Do proxy servers require a domain? In Norton's LiveUpdate program,
there is a place to enter a proxy server name, port, user, and password, but
no place for a domain.
 
R

Roger Willcocks

Sample from MSDN:
Dim myCred As New
NetworkCredential(SecurelyStoredUserName,SecurelyStoredPassword,Securely
StoredDomain )

Dim myCache As New CredentialCache()

myCache.Add(New Uri("www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("app.contoso.com"), "Basic", myCred)

Dim wr As WebRequest = WebRequest.Create("www.contoso.com")
wr.Credentials = myCache


Off on a client site just now, so I can't check how we did it, but this
looks right.

I know using CredentialCache.DefaultCredentials doesn't work



Roger Willcocks
Software Engineer
http://www.L-Space-Design.com/
"Putting your experience to work"
 
M

Mike

Thanks. That code is for authenticating a request to a web server - I don't
need to do this - I just need to authenticate with the proxy server. Would
I specify the proxy server address for the Uri argument?
 
M

Mike

I just found out that the .NET Compact Framework doesn't support the
CredentialCache class. I'd still like to hear from a Microsoft
representative about this.
 
M

Mike

I resolved the error by setting Credentials on the WebRequest object
(instead of the WebProxy object).
 

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