C# webclient and proxy server

前端 未结 7 482
情书的邮戳
情书的邮戳 2020-11-30 04:10

I am using a web client class in my source code for downloading a string using http.

This was working fine. However, the clients in the company are all connected now

7条回答
  •  日久生厌
    2020-11-30 04:14

    The answer proposed by Jonathan is proper, but requires that you specify the proxy credentials and url in the code. Usually, it is better to allow usage of the credentials as setup in the system by default (Users typically configure LAN Settings anyway in case they use a proxy)...

    The below answer has been provided by Davide in earlier answer, but that requires modifying the app.config files. This solution is probably more useful since it does the same thing IN CODE.

    In order to let the application use the default proxy settings as used in the user's system, one can use the following code:

    IWebProxy wp = WebRequest.DefaultWebProxy;
    wp.Credentials = CredentialCache.DefaultCredentials; 
    wc.Proxy = wp;
    

    This will allow the application code to use the proxy (with logged-in credentials and default proxy url settings)... No headaches! :)

    Hope this helps future viewers of this page to solve their problem!

提交回复
热议问题