1
更新:我试过HttpWebRequest并且它也表现出相同的行为。WebClient DownloadStringAsync加载非常缓慢
我试图使用WebClient DownloadStringAsync检索Outlook加载项(VSTO/.Net 4.0)中的一些(非常小的)数据。它甚至在发出请求之前需要大约10-15秒。
利用谷歌的权力,我指出了它试图拿起代理设置的事实,我应该将它们设置为空。我想,无论是在代码:
WebClient serviceRequest = new WebClient();
serviceRequest.Proxy = null;
,并通过添加一个App.config文件,并把:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>
</configuration>
我通过“新建项目”界面添加的文件(我不知道它被拾起和利用)。
这些解决方案都没有工作。有什么我可以尝试改变的。
有问题的代码如下:
class MyClient
{
string url = "http://192.168.1.99:4567/contact.json?token={0}&email={1}";
WebClient serviceRequest = new WebClient();
public void getContact(string email, DownloadStringCompletedEventHandler methodName)
{
Uri target = new Uri(String.Format(url, "1234", email));
serviceRequest.Proxy = null;
if(serviceRequest.IsBusy)
{
serviceRequest.CancelAsync(); // Changed our mind and switched email
}
serviceRequest.DownloadStringCompleted += methodName;
serviceRequest.DownloadStringAsync(target);
}
}