Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Empty HttpWebResponse length for some urls

Empty HttpWebResponse length for some urls

Scheduled Pinned Locked Moved Web Development
htmldatabasecomquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Manfield
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • J Jason Manfield

      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?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • M minhpc_bk

        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.

        J Offline
        J Offline
        Jason Manfield
        wrote on last edited by
        #3

        Thanks. Setting UserAgent helped.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups