4
Good afternoon my dear, I need to make a request for an api that stays in an external domain the local network, I perform this through a webrequest that was created this way:
WebRequest myWebRequest = WebRequest.Create("urldestino");
However, the network has a proxy, which barred my requests informing that proxy authentication was necessary. To test the operation, I was able to perform the request by manually setting the proxy in the following way:
WebProxy myProxy = new WebProxy();
myProxy = (WebProxy)WebProxy.GetDefaultProxy();
myProxy.Credentials = new NetworkCredential("meuusuario", "minhasenha", "meudominio");
myWebRequest.Proxy = myProxy;
Detail: after the execution of "myProxy = (WebProxy)WebProxy.GetDefaultProxy();"
myProxy.Credentials was null, so I manually set.
In this way, the request goes through the proxy, but I was directed to get the proxy session already authenticated by windows, in the same way that browsers and Postman do, in Postman for example I perform the request without the need to inform the proxy data and it does not return me a proxy Authentication is required.
Is there any way I can get the proxy session authenticated without having to manually pass the registration and password of the logged in users?
From now on I thank you very much.
The proxy is configured in Windows and is default?
– Jéf Bueno
I believe so, it is set in the browser to "use automatic configuration script" and below is set its address.
– André Luiz
So you don’t need any code, the default of Webrequest is to use the proxy configured in the OS. I will not put as an answer because I have no way to test it now, but test there and leave a feedback in the comments =D
– Jéf Bueno
It is not getting automatic, I believe it would get in myProxy = (Webproxy)Webproxy.Getdefaultproxy(); however myproxy does not receive the credentials already configured, and by not passing the credentials I received a "{"The remote server returned an error: (407) Proxy Authentication Required."}"
– André Luiz