C# auto detect proxy settings

后端 未结 8 749
遇见更好的自我
遇见更好的自我 2020-12-01 06:37

C# 2008 SP1

I am using the code to detect if a proxy has been set under \"Internet Options\". If there is a proxy then I will set this in my webclient.

So I

8条回答
  •  生来不讨喜
    2020-12-01 07:25

    Try the following:

    public string GetMeMyInfo(string searchCriteria)
    {
        // Instatiate the web service and declare the necessary variables
        WsService.WsServiceBus oWsGetInfo = new WsService.WsServiceBus();
        // Configure the Web Service Proxy
        oWsGetInfo.Proxy = System.Net.WebProxy.GetDefaultProxy();
        oWsGetInfo.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
        // Invoke the web service
        return oWsGetInfo.GetInfo4Me(searchCriteria);
    }
    

    That will get the default proxy setting and credentials before invoking your web service for example.

提交回复
热议问题