2014-04-08 51 views
0

使用WebClient向服務器發出請求。webclient用於向服務器發出請求,但返回ERROR

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) 

回答

2

從您錯誤似乎你正在創建一個帶有錯誤URL的Web請求。

請確保在web.DownloadString(partialUrl); url字符串必須以適當的協議(http,https等)開頭

+0

啊非常好的謝謝你的幫助。 – John

相關問題