【问题标题】:webclient used to make a request to server but returns ERRORwebclient 用于向服务器发出请求但返回 ERROR
【发布时间】:2014-04-08 13:21:53
【问题描述】:

使用WebClient 向服务器发出请求。

WebClient web = new WebClient();
string xmlString = web.DownloadString(partialUrl);

partialUrl 返回一个有效的 URL,如果我在浏览器中使用它会返回正确的 XML 列表,但如果在 Visual Studio 中从调试模式运行,则会引发错误:

{System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
   at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
   at System.Net.WebRequest.Create(Uri requestUri)
   at System.Net.WebClient.GetWebRequest(Uri address)
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at System.Net.WebClient.DownloadString(String address)
   at Synchroniser.XML.GalwayPortal.Download_POS(String partialUrl, IInterpreter interpreter)

【问题讨论】:

    标签: c# asp.net asp.net-mvc-3 webclient


    【解决方案1】:

    从您的错误看来您正在使用错误的 url 创建一个 Web 请求。

    请确保在 web.DownloadString(partialUrl); url 字符串必须以正确的协议开头,例如(http、https 等)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      相关资源
      最近更新 更多