c# – 提供了无效的请求URI.请求URI必须是绝对URI或必须设置BaseAddress

前端之家收集整理的这篇文章主要介绍了c# – 提供了无效的请求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,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_....
原文链接:https://www.f2er.com/csharp/98907.html

猜你在找的C#相关文章