Help me...How to read the content if "Transfer-Encoding:chunked" is used?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VeeraLakshmi
    New Member
    • Mar 2007
    • 3

    Help me...How to read the content if "Transfer-Encoding:chunked" is used?

    I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.If the HTTP header contains Content-Length,am getting the content length as below:

    Code:
    public class HTTPResponseReader extends HTTPMessageReader
     {
        String statusCode;
        public HTTPResponseReader(InputStream istream) throws IOException,                     NoSuchElementException 
     {
      BufferedInputStream distream = new BufferedInputStream(istream);
      retrieveHeader(distream);
      StringTokenizer st =  new StringTokenizer(new String(HTTPMessageReader.toArray(header)));
      versionProtocol = st.nextToken();
      statusCode = st.nextToken();
      String s;
      while (st.hasMoreTokens()) 
      {
            s = st.nextToken();
            if (s.equals("Transfer-Encoding:"))
            {
    	  transferEncoding = new String(st.nextToken());
    	}
    	if (s.equals("Content-Length:"))
    	{
    	  contentLength = Integer.parseInt(st.nextToken());
            } 
    	if (s.equals("Connection:")) 
    	{
    	 connection = new String(st.nextToken());
    	 if (connection.equals("keep-alive")) mustCloseConnection = false;
    	}
       }
       retrieveBody(distream);	
      }
    }


    After getting the Content-Length,i used read method to read the content upto that content length.Then i concatenated the HTTP header and body and the requested site was opened.But some sites dont have Content-Length.Instead of that,Transfer-Encoding is used.I got the HTTP Response header as "Transfer-Encoding:chunke d" for some sites.If this encoding is used how to get the length of the message body and how to read the content.
    Can anybody help me.
    Thanks in advance...
Working...