我试图使用此代码从网页获取内容:
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,response.Length - 1); source = WebUtility.HtmlDecode(source); HtmlDocument resultat = new HtmlDocument(); resultat.LoadHtml(source);
但我得到这个错误:
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
解决方法
您只需要指定完整的URL(包括协议),如下所示:
var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_....