如何关闭自动代理检测中的`AmazonS3`对象? [英] How to turn off the automatic proxy detection in the `AmazonS3` object?

查看:261
本文介绍了如何关闭自动代理检测中的`AmazonS3`对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用的第一次的 AmazonS3 对象的应用程序启动后,有一个大的延迟约14秒。这个大时间延迟并不present随后所有的电话。

When using the AmazonS3 object for the first time after the application starts, there is a large delay of approx 14 seconds. This large time delay is not present for all subsequent calls.

我以前与其它HTTP相关的类遇到这种精确的延迟问题,上课的时候​​有问题试图确定本地计算机的代理设置它造成的,是否使用它们。

I have encountered this exact delay issue before with other HTTP related classes and it is caused when the class in question tries to determine the local machine's proxy settings and whether to use them or not.

要发生与 Web客户端,将 WebClient.Proxy = NULL停止这一点; ,它不尝试自动检测代理设置,但我无法弄清楚如何禁用 AmazonS3 对象的代理检测功能。

To stop this from happening with WebClient, you set WebClient.Proxy = null; and it doesn't try to auto detect the proxy settings, but I cannot figure out how to disable the proxy detection functionality of the AmazonS3 object.

我曾专门尝试设置的ProxyHost

_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey, new AmazonS3Config { ProxyHost = null });

没有工作。目前,我们正在使用亚马逊的.NET SDKv1.3.17.0。

Which didn't work. We are currently using the Amazon .NET SDK 'v1.3.17.0'.

有没有一种方法来关闭代理检测?

Is there a way to turn off the proxy detection?

推荐答案

好问题 - 我还没有尝试过自己,只有分析了code,但<一个href="http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/html/T_Amazon_S3_AmazonS3Config.htm"相对=nofollow> AmazonS3Config类使用私有方法 configureWebRequest(),而这又依赖于的 WebRequest类来处理实际的HTTP连接。现在,的WebRequest 拥有的 WebRequest.DefaultWebProxy物业,这是公共静态(例如,你可以在调用之前设置此应用程序中的 CreateAmazonS3Client(()):

Good question - I haven't tried it myself and only analyzed the code, but the AmazonS3Config Class uses a private method configureWebRequest(), which in turn relies on the WebRequest Class to handle the actual HTTP connection. Now, WebRequest has a WebRequest.DefaultWebProxy Property , which is public static (i.e. you can set this within your application before calling CreateAmazonS3Client(()) :

在DefaultWebProxy属性获取或设置全局代理。该   DefaultWebProxy属性决定在默认代理所有   WebRequest的实例使用该请求是否支持代理和无代理   设定明确使用Proxy属性。 [重点煤矿]

The DefaultWebProxy property gets or sets the global proxy. The DefaultWebProxy property determines the default proxy that all WebRequest instances use if the request supports proxies and no proxy is set explicitly using the Proxy property. [emphasis mine]

代理自动检测您遇到假想诱发相应的IE浏览器的行为:

The proxy auto detection you are experiencing is supposedly induced by the respective IE behavior:

在DefaultWebProxy属性读取在app.config代理设置   文件。如果没有配置文件,当前用户的Internet Explorer   (IE)代理设置使用。

The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file, the current user's Internet Explorer (IE) proxy settings are used.

因此​​我希望,这可以以类似的方式与 WebClient.Proxy物业你提到,尽管在类级别,事实上强烈的最后一段建议:

Consequently I'd hope that this can be disabled in a similar way as for the WebClient.Proxy Property you mentioned, albeit on the class level, as indeed strongly suggested by the last paragraph:

如果该DefaultWebProxy属性设置为null,所有后续   WebRequest类的实例按创建创建或   CreateDefault方法没有代理 [重点煤矿]

If the DefaultWebProxy property is set to null, all subsequent instances of the WebRequest class created by the Create or CreateDefault methods do not have a proxy. [emphasis mine]

添加人blexandre

这是这个答案示例code会

sample code from this answer would be

System.Net.WebRequest.DefaultWebProxy = null;
_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey);

注意的,这将禁用代理为每一个Web请求, _client 使用它,所以它是安全的话,这是创建的,但要小心,如果你可能有未决更多的要求的WebRequest

Note that this will disable the proxy for every web request, _client is created using it, so it is safe to do this, but be careful if you might have more requests pending from the WebRequest class

这篇关于如何关闭自动代理检测中的`AmazonS3`对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆