Empty HttpWebResponse length for some urls
-
For some URLs (e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634), the content length for the HttpWebResponse I get with request.GetResponse in empty. The response.GetResponseStream() also empty. Here is the code snippet: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); string pageData = sr.ReadToEnd(); The Content Type for the response is "text/html; charset=iso-8859-1" and the HttpStatusCode was OK. What am I missing?
-
For some URLs (e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634), the content length for the HttpWebResponse I get with request.GetResponse in empty. The response.GetResponseStream() also empty. Here is the code snippet: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); string pageData = sr.ReadToEnd(); The Content Type for the response is "text/html; charset=iso-8859-1" and the HttpStatusCode was OK. What am I missing?
Hi Jason, There's one more thing that you need to do is to add the value of the
User-Agent
to the header of the http request. The sample code looks something like this:HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
//or whatever like this:
//req.UserAgent=".NET Framework Test Client";HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
There's also another work-around solution is to use the Web Browser control to navigate to the site, then you can read the output as soon as the document gets loaded completely.
-
Hi Jason, There's one more thing that you need to do is to add the value of the
User-Agent
to the header of the http request. The sample code looks something like this:HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
//or whatever like this:
//req.UserAgent=".NET Framework Test Client";HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
There's also another work-around solution is to use the Web Browser control to navigate to the site, then you can read the output as soon as the document gets loaded completely.
Thanks. Setting UserAgent helped.