HTTPClent 错误提供了无效的请求 URI

HTTPClent error An invalid request URI was provided

我正在尝试使用以下代码从网页获取内容:

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);

但是我得到这个错误:

An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.

绝对 URI 遵循 protocol://server/path?query#hash 约定。由于您没有指定协议,特别是 http://https:// 在您的情况下, URL 不是绝对的,因此无法解决。

您只需像这样指定完整的 URL(包括协议):

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