Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 427
Ehsan Akbar Avatar asked Jan 16 '16 11:01

Ehsan Akbar


1 Answers

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

var response = await http.GetByteArrayAsync("http://www.nsfund.ir/news?p_.... 
like image 107
Yacoub Massad Avatar answered Sep 19 '22 09:09

Yacoub Massad