Hi, all
I have a problem of the following kind.
There's a remote server that can be accessed via HTTPS (say,
https://remoteserver). This server doesn't allow anonymous users, so I have
to connect to it using some username/password.
There's a .NET client that must access this remote server and this client
can go to the Internet only through Proxy Server. This Proxy Server doesn't
require authentication.
And now what happens: .Net client doesn't work properlym receiving
401-Unauthorized while trying to connect to remote server.
However:
1. Running IE from the same client machine (and using the same Proxy
Server), user can connect to remote server just fine
2. If .NET client is configured to bypass proxy server, it can connect to
remote server just fine
3. .NET client can connect (via Proxy Server) to the same remote server via
http.
4. .NET client can connect (via Proxy Server) to any other https site if it
allows anonymous access.
Taking above into account, it seems that the problem is with passing the
credentials through Proxy Server. Does anyone have ideas?
Now here's the code:
string url = "https://remoteserver";
string proxyurl = "some.proxyserv er.url:8080";
NetworkCredenti al c = new NetworkCredenti al("user", "password", "domain");
try
{
WebProxy p = new WebProxy(proxyu rl, false);
p.Credentials = CredentialCache .DefaultCredent ials;
HttpWebRequest req = (HttpWebRequest )HttpWebRequest .Create(url);
req.Proxy = p;
req.Credentials = c;
req.PreAuthenti cate = true;
req.KeepAlive = true;
using(HttpWebRe sponse resp = (HttpWebRespons e)req.GetRespon se())
{
Console.WriteLi ne(resp.StatusC ode);
}
}
catch(Exception ex)
{
Console.WriteLi ne(ex);
}