WebClient请求c#wp7 Uri.length期间发生异常非常长

时间:2012-09-04 16:24:35

标签: c# windows-phone-7 uri webclient

问题在于,如果我执行Webclient.DownloadStringAsync(Uri),而Uri.length很长,我会看到错误:An exception occurred during a WebClient request

对于Webclient的URI是对链接长度的限制吗? 如果链接很长怎么办?

WebClient queueItem_client = new WebClient();
queueItem_client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(queueItem_client_DownloadStringCompleted);
            queueItem_client.DownloadStringAsync(execUri);

void queueItem_client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{}

execUri个链接长度为2234个字符。

enter image description here

如果execUri由大约500个字符组成,那么就会出现正常响应。 enter image description here

1 个答案:

答案 0 :(得分:3)

某些浏览器对URI实施限制。见What is the maximum length of a URL in different browsers?。如果可能长的Uri(超过2000个字符)考虑将此请求更改为Post而不是GET并将您的参数放入正文中。