Disable proxy for entire application?

2019-02-20 03:36发布

问题:

Ever since upgrading to Visual Studio 2010, I'm running into an issue where the first web request of any type (WebRequest, WebClient, etc.) hangs for about 20 seconds before completing. Subsequent calls work quickly. I've narrowed down the problem to a proxy issue.

If I manually disable proxy settings, I don't experience this delay:

Dim wrq As WebRequest = WebRequest.Create(Url)
wrq.Proxy = Nothing

What's strange is that there are no proxy settings enabled on this machine in Internet Options. What I'm wondering is if there is a way to disable proxy settings for my entire project in one shot without explicitly disabling as above for every web object.

The main reason I want to be able to do this is that I'm trying to use an API (http://code.google.com/p/google-api-for-dotnet/) which uses web requests, but does not provide any way to manually disable proxy settings.

I have found some information suggesting that I need to add some proxy information to the app.config file, but I get errors building my program if I make an edits to that file.

Can anyone point me in the right direction?

回答1:

Brent - that's the correct solution : adding a defaultProxy element to your application's configuration file.

So for a website, it's the web.config. For an .exe application, it's .config.

And those settings are also correct :-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.net>
        <defaultProxy enabled="false" useDefaultCredentials="false">
            <proxy/>
            <bypasslist/>
            <module/>
        </defaultProxy>
    </system.net>
</configuration>


回答2:

Instead of turning off the proxy setting altogether you can try using the bypasslist to turn it off for the servers that you're having problems with.
See http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx for details and a sample.

If you're having problems changing the app.config I suggest posting the errors and possibly the app.config as well.