3
var uri = new Uri("http://store.scrapbook.com/cos-pad825.html?t12-13=cosmo%20cricket&date=20110309");
var request = (HttpWebRequest)WebRequest.Create(url);
var cookieContainer = new CookieContainer();

request.CookieContainer = cookieContainer;
request.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5";
request.Method = "GET";
request.AllowAutoRedirect = true;
request.Timeout = 15000;

var response = (HttpWebResponse)request.GetResponse();
var page = new HtmlDocument();
var stream = response.GetResponseStream();
page.Load(stream);

Causes an error. on the Load(stream) call. Any ideas?

Adrian Adkison
  • 3,537
  • 5
  • 33
  • 36
  • Here is the stack trace at HtmlAgilityPack.HtmlDocument.ReadDocumentEncoding(HtmlNode node) at HtmlAgilityPack.HtmlDocument.PushNodeEnd(Int32 index, Boolean close) at HtmlAgilityPack.HtmlDocument.Parse() at HtmlAgilityPack.HtmlDocument.Load(TextReader reader) – Adrian Adkison Mar 18 '11 at 09:19
  • I think the best option for you is to debug this code. Get source code from codeplex and debug. – Rafal Spacjer Mar 18 '11 at 09:40

2 Answers2

3

The error I get when I run your code is:

System.ArgumentException: 'ISO-8559-1' is not a supported encoding name.

It's thrown by the standard .NET Framework encoding classes. It means the page declares an encoding not supported by .NET. I fixed it like this:

var page = new HtmlDocument();
page.OptionReadEncoding = false;

PS: I'm using the Html Agility Pack version 1.3

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
0

Maybe not a the answer you need, but the stack trace indicates the exception occurred after you past the response stream type to the page's load method.
It might be worth adding a TextReader in before the htmldocument assignment, and pass off the stream object to that. Then pass the textreader var to htmldoc's Load method.

Before you debug the source code for latest htmlagility, I think you should first edit your question to include the states of all types/props of interest, for clarity.

Anonymous Type
  • 3,051
  • 2
  • 27
  • 45