c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置Base
发布时间:2020-12-15 18:33:56 所属栏目:百科 来源:网络整理
导读:我试图使用此代码从网页获取内容: 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
我试图使用此代码从网页获取内容:
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); 但我得到这个错误:
解决方法
您只需要指定完整的URL(包括协议),如下所示:
var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_.... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |