How can I get WebClient (webservice client) to automatically use the default proxy server?

落花浮王杯 提交于 2019-12-05 00:59:55

Try adding

  <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>

to your app.config file

umarfarukhT
using (WebClient webClient = new WebClient())
{

    webClient.UseDefaultCredentials = true;
    webClient.Proxy = WebRequest.GetSystemWebProxy();
}

this should work

First try to use this:

WebProxy proxy = (WebProxy) WebRequest.DefaultWebProxy;
if (proxy.Address.AbsoluteUri != string.Empty)
{
    Console.WriteLine("Proxy URL: " + proxy.Address.AbsoluteUri);
    client.Proxy = proxy;
}

if this does not work try with:

WebProxy proxy = WebProxy.GetDefaultProxy()
client.Proxy = proxy;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!