HttpWebRequest with HTTPS URL over proxy

  • Thread starter Thread starter Praveen
  • Start date Start date
P

Praveen

Hi All,

I was facing problem using the HttpWebRequest class to make a connection to
a secure site with a proxy server. I am getting the below error

An unhandled exception of type 'System.NotSupportedException' occurred in
system.dll
Additional information: The ServicePointManager does not support proxies of
https scheme.

exception is thrown where the proxy is set to the webrequest object.

Thanks in advance,
Praveen

Code excerpt is :

System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();
HttpWebRequest WebReqt = (HttpWebRequest)HttpWebRequest.Create(strFileURL);
WebProxy WP = new WebProxy(WebReqt.Proxy.GetProxy(new Uri( strFileURL)));
WP.Credentials = CredentialCache.DefaultCredentials;
WebReqt.Proxy = WP;
 
Praveen said:
Hi All,

I was facing problem using the HttpWebRequest class to make a
connection to a secure site with a proxy server. I am getting the
below error

An unhandled exception of type 'System.NotSupportedException'
occurred in system.dll Additional information: The
ServicePointManager does not support proxies of https scheme.

exception is thrown where the proxy is set to the webrequest object.

Thanks in advance,
Praveen

Code excerpt is :

System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy(); HttpWebRequest WebReqt =
(HttpWebRequest)HttpWebRequest.Create(strFileURL); WebProxy WP =
new WebProxy(WebReqt.Proxy.GetProxy(new Uri( strFileURL)));

That's a very weird and wrong way of creating a WebProxy object. Simply
pass the proxy's (not the destination') URI to the constructor.


Cheers,
 
hello Joss,

if you read about GetProxy you would understand why this was done. This is
required when you want to use the browsers proxy setting. This is imp in
cases when the settings can be complex in a corporate environment where
different proxy is used for different sites.

I was expecting the below mentioned bug to be fixed in the .net framework
2.0 release but that is not the case. I still continue to get this error.

can someone help!

thanks and regards,
Praveen
 
Praveen said:
hello Joss,

if you read about GetProxy you would understand why this was done.

Well, talk about reading. For starters, the name is Joerg Jooss...
This is required when you want to use the browsers proxy setting.
This is imp in cases when the settings can be complex in a corporate
environment where different proxy is used for different sites.

But WebProxy.GetProxy() is a rather brittle API to do that. If you'd
ever try that with a host on the proxy's bypass list, it cannot work,
because you will receive the unproxied host's address. Maybe you're
better off retrieving and parsing your PAC file.

Cheers,
 
Hi Jooss I agree.
but thats not my issue right now. The problem that I am facing right now is
that while working with the https:// url I am getting an error "The
ServicePointManager does not support proxies of
https scheme". This error comes in the line where I am setting the Proxy for
the webrequest and not where the proxy object is created.

HttpWebRequest WebReqt = (HttpWebRequest)HttpWebRequest.Create(strFileURL);
WebProxy WP = new WebProxy("ProxyXYZ");
WP.Credentials = CredentialCache.DefaultCredentials;
WebReqt.Proxy = WP; // This line causes the error

I could not find a work around to get past this issue.

Regards,
Praveen
 
Hi

To troubleshoot the problem, I think we need to make sure the proxy works
well first.
You may to use IE to access to the https website via the proxy( you can set
it in the IE options) to see if that works for you.
And then you can try to use the code snippet as below to access to the
https website via proxy without use your own CertificatePolicy.

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Praveen said:
Hi Jooss I agree.
but thats not my issue right now. The problem that I am facing right
now is that while working with the https:// url I am getting an error
"The ServicePointManager does not support proxies of https scheme".
This error comes in the line where I am setting the Proxy for the
webrequest and not where the proxy object is created.

HttpWebRequest WebReqt =
(HttpWebRequest)HttpWebRequest.Create(strFileURL); WebProxy WP =
new WebProxy("ProxyXYZ"); WP.Credentials =
CredentialCache.DefaultCredentials; WebReqt.Proxy = WP; // This
line causes the error

I guess "ProxyXYZ" stands for some HTTPS URL? So you create a WebProxy
on a URL like https://host:port?

Cheers,
 
Back
Top