2016-01-16 99 views
3

我試圖用這個代碼從一個網頁的內容:提供了無效的請求URI。 URI必須是絕對URI或BaseAddress請求必須設置

HttpClient http = new HttpClient(); 
    var response = await http.GetByteArrayAsync("www.nsfund.ir/news?p_p_id=56_INSTANCE_tVzMoLp4zfGh&_56_INSTANCE_tVzMoLp4zfGh_mode=news&_56_INSTANCE_tVzMoLp4zfGh_newsId=3135919&p_p_state=maximized"); 
    String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1); 
    source = WebUtility.HtmlDecode(source); 
    HtmlDocument resultat = new HtmlDocument(); 
    resultat.LoadHtml(source); 

,但我得到這個錯誤:

提供了無效的請求URI。請求URI必須是絕對URI或BaseAddress必須設置。

+2

嘗試'HTTP:// WWW .......' –

回答

5

您只需要指定完整的URL(包括協議)是這樣的:

var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_.... 
4

絕對URI遵循protocol://server/path?query#hash約定。由於您沒有指定協議,特別是您的情況下爲http://https://,因此URL不是絕對的,因此無法解析。

相關問題