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

Ehsan Akbar picture Ehsan Akbar · Jan 16, 2016 · Viewed 44.8k times · Source

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.

Answer

Yacoub Massad picture Yacoub Massad · Jan 16, 2016

You simply need to specify the full URL ( including the protocol) like this:

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