Reputation: 7301
I am trying to get the content from a web page using this code :
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);
But I get this error :
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
Upvotes: 42
Views: 133999
Reputation: 27871
You simply need to specify the full URL ( including the protocol) like this:
var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_....
Upvotes: 37
Reputation: 41968
An absolute URI follows the protocol://server/path?query#hash
convention. As you did not specify a protocol, specifically http://
or https://
in your case, the URL is not absolute and thus cannot be resolved.
Upvotes: 16