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.
For .NET Framework 4.x:
HttpClient,HttpWebRequest, or even the horribleWebClientclass without any further trickery (e.g. customHttpMessageHandlerclasses that do HTTPS-to-HTTP conversion themselves, or other attempts at implementing proxy logic)app.config(orweb.configif your application runs within IIS) with the<defaultProxy>element and one-or-more child<proxy />elements:For .NET Core 3.0 or later, .NET 5, and .NET 6, and later:
HttpClient.DefaultProxyto allow applications to gain custom HTTP proxy logic by implementingSystem.Net.IWebProxythemselves and and passing a reference into thestatic IWebProxy DefaultProxy { get; set; }property inHttpClient(ideally only once, during application startup).System.Net.WebProxywhich you can use without reimplementingIWebProxybtw.<defaultProxy>inapp.configas .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, andNO_PROXY.HttpClient.DefaultProxy.System.Net.WebProxyto be pre-configured and passed intoHttpClient.WebProxyalready for you.