Web客户端用于向服务器发出请求,但返回错误
本文关键字:请求 返回 错误 客户端 用于 服务器 Web | 更新日期: 2023-09-27 17:57:16
使用WebClient
向服务器发出请求。
WebClient web = new WebClient();
string xmlString = web.DownloadString(partialUrl);
该partialUrl
返回一个有效的URL,如果我在浏览器中使用该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)
从你的错误 您似乎正在使用错误的 url 创建 Web 请求。
请确保在网络中。下载字符串(部分网址);URL 字符串必须以正确的协议开头,例如(http,https 等)