Results 1 to 6 of 6
  1. #1
    jmu2101 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default Read content from URL with an http response code=204

    I am trying to read from a website, and the server returns a response code of 204, which is supposed to mean there is no content, despite that the site has content. What is going on? And is there any way to access the html of a site with a 204 response code, to ignore the response code, or at least to get around it in some way?
    Last edited by jmu2101; 09-27-2011 at 12:40 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Read content from URL with an http response code=204

    How do you know the site has content? Without more information - code, the site you are accessing, etc...it is difficult to troubleshoot.

  3. #3
    jmu2101 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default Re: Read content from URL with an http response code=204

    I know there's content because if i go on the web manually and view source on my browser, i can see the html.

  4. #4
    jmu2101 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default Re: Read content from URL with an http response code=204

    URL hef=new URL(my website);
    BufferedReader kj=null;
    int kjkj=((HttpURLConnection)hef.openConnection()).get ResponseCode();
    System.out.println(kjkj);
    String j=((HttpURLConnection)hef.openConnection()).getRes ponseMessage();
    System.out.println(j);
    URLConnection g=hef.openConnection();
    g.connect();

    try{
    kj=new BufferedReader(new InputStreamReader(g.getInputStream()));


    while(kj.readLine()!=null)
    {
    String y=kj.readLine();

    System.out.println(y);
    }
    }

    finally
    {
    if(kj!=null)
    {
    kj.close();
    }
    }


    }

    }

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Read content from URL with an http response code=204

    Some sites (again you do not mention which site you wish to access, so no one can reproduce your problem to troubleshoot) require appropriate headers to be sent. Try setting certain headers, for example the User agent header corresponding to your browser (google these keywords for more information on how to do this - lots of code snippets out there)

  6. #6
    jmu2101 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default Re: Read content from URL with an http response code=204

    Quote Originally Posted by doWhile View Post
    Some sites (again you do not mention which site you wish to access, so no one can reproduce your problem to troubleshoot) require appropriate headers to be sent. Try setting certain headers, for example the User agent header corresponding to your browser (google these keywords for more information on how to do this - lots of code snippets out there)
    This helps very much. Thanks.

Similar Threads

  1. Server returned HTTP response code: 500.. i need help
    By hardc0d3r in forum Java Servlet
    Replies: 9
    Last Post: 03-12-2012, 08:08 PM
  2. Server returned HTTP response code: 500
    By fuliangQ in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-09-2009, 03:55 AM
  3. HTTP response not read
    By SD_Be in forum Networking
    Replies: 1
    Last Post: 03-10-2009, 04:36 PM
  4. java.io.Exception: Server returned HTTP response code: 403
    By navishkumarb in forum Advanced Java
    Replies: 1
    Last Post: 01-05-2008, 01:33 PM
  5. Server returned HTTP response code: 500
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-09-2007, 04:32 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •