Our VPC of company using an http system proxy. Due to the fact, there are no https proxy and any web links should using http proxy even it is a https.
I tried to add these two solutions to my C# code, but it doesn't help.
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
or
ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
Some Details.
I also write a python code by O365 graph api python.
Solution is quiet simple.
Change connection.py source code from
if proxy_server and proxy_port:
if proxy_username and proxy_password:
self.proxy = {
"http": "http://{}:{}@{}:{}".format(proxy_username,
proxy_password,
proxy_server,
proxy_port),
"https": "https://{}:{}@{}:{}".format(proxy_username,
proxy_password,
proxy_server,
proxy_port),
}
else:
self.proxy = {
"http": "http://{}:{}".format(proxy_server, proxy_port),
"https": "https://{}:{}".format(proxy_server, proxy_port),
}
to
if proxy_server and proxy_port:
if proxy_username and proxy_password:
self.proxy = {
"http": "http://{}:{}@{}:{}".format(proxy_username,
proxy_password,
proxy_server,
proxy_port),
"https": "http://{}:{}@{}:{}".format(proxy_username,
proxy_password,
proxy_server,
proxy_port),
}
else:
self.proxy = {
"http": "http://{}:{}".format(proxy_server, proxy_port),
"https": "http://{}:{}".format(proxy_server, proxy_port),
}
System works.
HttpClient
, HttpWebRequest
, or even the horrible WebClient
class without any further trickery (e.g. custom HttpMessageHandler
classes that do HTTPS-to-HTTP conversion themselves, or other attempts at implementing proxy logic)app.config
(or web.config
if your application runs within IIS) with the <defaultProxy>
element and one-or-more child <proxy />
elements:<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="false">
<proxy autoDetect="false" bypassOnLocal="false" proxyAddress="http://your-proxy-server:1234" useSystemDefault="false" />
</defaultProxy>
</system.net>
</configuration>
HttpClient.DefaultProxy
to allow applications to gain custom HTTP proxy logic by implementing System.Net.IWebProxy
themselves and and passing a reference into the static IWebProxy DefaultProxy { get; set; }
property in HttpClient
(ideally only once, during application startup).
System.Net.WebProxy
which you can use without reimplementing IWebProxy
btw.<defaultProxy>
in app.config
as .NET Framework's traditional XML-based configuration feature was removed, instead you can configure process-wide HTTP/HTTPS proxy settings by setting any of these environment variables: HTTP_PROXY
, HTTPS_PROXY
, ALL_PROXY
, and NO_PROXY
.
HttpClient.DefaultProxy
.System.Net.WebProxy
to be pre-configured and passed into HttpClient.WebProxy
already for you.