I'm trying to connect to a website using WebRequest and a proxy that has basic Authorization. When connecting to a http site works fine but if I try to connect to a https site get 401 error, looking at network monitor when I try to connect to a https site, don't know why the Authorization header its not present.
Already tried add NetworkCredentials at both proxy and WebRequest no luck either.
IWebProxy proxy = new WebProxy("http://proxyaddress:port");
HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(WEBSERVICE_URL);
conn.Method = "GET";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("username:password"));
conn.Headers.Add("Authorization", "Basic " + encoded);
conn.PreAuthenticate = true;
conn.Proxy = proxy;
conn.GetResponse();
I had this issue recently where our company proxy stripped Basic auth headers (since it is not secure) when making an external API request to prevent leakage, the only way around this was to order a developer proxy for that URL so that there where no authentications or interceptions. If you have access to the proxy try to configure it to allow Basic auth.
Related
We have implemented the proxy server for calling the third party website which is currently happening through firewall rule. We have added the Service account to Proxy server ,URL is whitelisted and IE browser has the Proxy set up.
Whenever we are calling the third party website , we are getting the 407 Authentication from proxy server and application running by Service account identity.
Is there anything like Microsoft is not allowing to pass the credentials to the proxy server ?
*Application deployed in IIS 10
*Asp.net web form
*Windows server 2016
Regarding the error 407 proxy authentication required, you can try to define a proxy class first, then set the Credentials property of the proxy object, and finally assign the defined proxy object to the Proxy proxy property of the Web Service object.
WebProxy proxy = new WebProxy(proxyAddress);
proxy.Credentials = new NetworkCredential("username", "password", "domain");
proxy.UseDefaultCredentials = true;
WebRequest.DefaultWebProxy = proxy;
HttpWebRequest request = new HttpWebRequest();
request.Proxy = proxy;
I have a problem requesting HTTPS service over the internet on some client, when I try to do it the exception is thrown that "The ServicePointManager doesn't support proxies with the https scheme". On some clients my code works fine, but on some it fails with the exception. I think customers for whom the code works fine have http proxy, and https traffic comes through the http proxy, which is perfectly fine.
This function creates a new request:
var req = (HttpWebRequest)WebRequest.Create(url);
// This thing is needed to get default proxy
// and user credentials written in iexplore
var proxy = req.Proxy;
if(proxy != null) {
var puri = proxy.GetProxy(req.RequestUri);
var prox = new WebProxy(puri.ToString());
prox.Credentials = CredentialCache.DefaultCredentials;
req.UseDefaultCredentials = true;
req.Proxy = prox;
}
// Setting up custom cookies and UA
req.CookieContainer = Config.Cookies;
req.UserAgent = Config.UserAgent;
This is how I'm accepting all certificates:
ServicePointManager.ServerCertificateValidationCallback =
(sender, cert, chain, sslpolicy) => true;
It seems that ServicePointManager doesn't infact support working with proxies over https. How can I fix this issue? What if I somehow make the https WebRequest go through the http proxy instead of https, will this work, if so how can I do it?
Yes, you are right, It seems like The ServicePointManager does not support proxies of the https scheme.
If you change the scheme from HTTPS to HTTP it will work fine.
It's only an initial request between the client and proxy that is not secure or over SSL. The traffic tunneled through the proxy is encrypted or no depending on the server.
If you are trying to access any SSL server through the HTTP proxy, the traffic is still encrypted.
Let say if you are trying to access the HTTP server through HTTPS proxy still, the traffic is not encrypted.
I am trying to access service bus via a squid3 webproxy with Basic authentication enabled in the proxy using C#
i am using below code to set the web proxy
webproxy webproxy = new webproxy("http://weproxyuri:port", false);
webproxy.credentials = new networkcredential("username", "password","domain");
WebRequest.DefaultWebProxy = webProxy
i am using below code to access service bus
MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(connectionstring);
QueueClient queueSendClient = messagingFactory.CreateQueueClient(queuename);
var bm1 = queueSendClient.Peek();
access of service bus is failing with error - The X.509 certificate CN=servicebus.windows.net is not in the trusted people store
in the proxy log i am seeing 1454679317.842 0 10.168.84.150 TCP_DENIED/407 4046 GET http://www.microsoft.com/pki/mscorp/msitwww2.crt - HIER_NONE/- text/html
in the network traces i am seeing host trying to connect to http://www.microsoft.com/pki/mscorp/msitwww2.crt first it is trying to connect with out authentication then proxy is saying HTTP/1.1 407 Proxy Authentication required as a response to the request for this ideally host should resend the request with Proxy-Authorization Header which contains username and password but i am seeing a weird behavior where host is not send the Proxy-Authorization Header in the second time
any registry key needs to be set ?
i am using windows core 2012 R2 as host
this issue is fixed in 3.0.50496.1 or higher version of Microsoft.ServiceBus.dll
I am trying to create a console app that will automatically post something on my blog.
I 'm following step by step this guide https://developers.google.com/blogger/docs/2.0/developers_guide_dotnet
Sample source from google can be found here:
http://google-gdata.googlecode.com/svn/trunk/clients/cs/samples/blogger/ConsoleSample.cs
I am using ClientLogin authentication but I am behind my company's proxy.
Luckily the proxy is configured in IE settings so I am using
IWebProxy myProxy = WebRequest.DefaultWebProxy;
How can I configure the requests to the Blogger Service to use myProxy ?
Normally I would do it like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
IWebProxy myProxy = WebRequest.DefaultWebProxy;
request.Proxy = myProxy;
But now i have to alter the Blogger API's client libraries to use myProxy in every request
. Any ideas on how to do that?
Following the idea about using a WebProxy to make an http request to a server by IP address as demonstrated in the following answers :
Request Web Page in c# spoofing the Host
Http Request - Bypass DNS [.Net]
I'm trying to achive the same goal with an HTTPS request. I would like to still use an HttpWebRequest object in order to let the system automatically manage the certificate validation.
Unfortunately, this is not working and I get a System.Net.WebException with WebExceptionStatus.Timeout status.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"https://www.mywebiste.net/"
);
System.Net.WebProxy proxy = new WebProxy(
"192.168.3.14"
, 443 // HTTPS
);
request.Proxy = proxy;
WebResponse response = request.GetResponse()
Any Help appreciated.
TIA.
Try setting BYPassOnLocal as false.
http://msdn.microsoft.com/en-us/library/234s6ee9.aspx