I've an application that calls some services through a web-proxy. I'd like to show the information about the proxy used for requests. How can I do this?
My code is like the follow:
WebRequest request = WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
log(response.StatusDescription);
// HERE I'd like something like log(request.getProxy()))
reponse.Close();
Any idea? Thanks.
Proxy can be configured for the whole application and can be overridden for certain WebRequest
.
For the application it can be obtained by this code (it looks like it is your case):
IWebProxy appProxy = WebRequest.DefaultWebProxy;
For a certain WebRequest
:
IWebProxy requestProxy = request.Proxy;
Then you can log the information from that IWebProxy
:
string proxyAddress = appProxy.GetProxy(new Uri(url)).ToString();
Console.WriteLine(proxyaddress);