Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Question Reading A Response From A Web Browses HTTP Request

    I have asked a similar question a couple of days ago but I think I did not ask the question very well. I am trying to read the full header of an HTML request. Most of the examples that I read has terminated the while loop when seeing a "GET" returned from the client (Line 5 that is commented out). This is fine if you do not want to read the full header that is being send. My problem is that if I try and read the full head (and / or any data sent in a "POST") this loop hangs just after it see the four byte (13,10,13,10) that signify the end of the header. Which in turn means that I an unable to send a response back the client (which in my case is a web browser). I don't understand how I am to terminate the loop if I want the whole header and data if my socket receives an HTML "POST" request.

    Java Code:
    				
    BufferedReader clientInput = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    StringBuilder sbRequest = new StringBuilder();
    String sReadLine = null;
    while ((sReadLine = clientInput.readLine()) != null) {
            //if(sReadLine.contains("GET")) break;
    	sbRequest.append(sReadLine + "\n");
    }
    Sorry if this question is in the same vain as a previous one that I post. I just need some help understanding what is going on.

    Thanks in advance,
    Harold Clements
    Last edited by haroldjclements; 10-12-2011 at 02:09 PM. Reason: Typo

  2. #2
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Reading A Response From A Web Browses HTTP Request

    I think problem is after GET code you see the \n.

    readLine() method terminates when sees \n(newLine character) in buffer.

    HEADER=> GET \number .....
    You can only see GET then readline gives null so loop exit.

  3. #3
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Reading A Response From A Web Browses HTTP Request

    I can recommend you to use always bytes in network streams

Similar Threads

  1. Servlet request and Response Size
    By giladma in forum Java Servlet
    Replies: 0
    Last Post: 09-23-2011, 03:27 PM
  2. How request and response objects are forwarded
    By Matang in forum Java Servlet
    Replies: 3
    Last Post: 03-28-2011, 12:10 PM
  3. MDB/JMS Request/Response
    By rkands in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-04-2010, 02:38 PM
  4. HTTP response not read
    By SD_Be in forum Networking
    Replies: 1
    Last Post: 03-10-2009, 04:36 PM
  5. passively and quickly capturing request/response
    By sideswipe091976 in forum Networking
    Replies: 1
    Last Post: 07-10-2008, 01:01 AM

Posting Permissions

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