You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Vishwas <vi...@savinaya.com> on 2005/05/08 17:31:05 UTC

Wierd results when writing response headers to browser

Hi,
 
In a simple request-response sequel between the browser --> HttpClient
--> Host, I read the response headers (prepend it with StatusLine), the
response body as bytes and write it back to the browser (which
originated the requests) in that order. I have ensures per RFC that CRLF
follows each response header and an additional one at the end of
response headers.
 
I continuously get Connection Reset By Peer exception if I write the
response to the browser. If I dont write the response headers,
everything works just fine except that there are some websites I cannot
access which set cookies/ create URLs using Javascripts. I guess I have
hit a dead end thinking on this....Thoughts? Suggestions? Appreciate
your time in advance.
 
--------------------
here 'client' is a class where I instantiate HttpClient, 'out' is
browser socket
    String responseHeaders = client.getResponseHeaders(); (This is
parsed string)
    if(responseHeaders != null)
        out.write(responseHeaders.getBytes());
       System.out.println("CUSTOM LOG :: Response Headers = " +
responseHeaders);
    byte data[] = new byte[2000];
    int count;
    while (( count  = in.read(data)) > 0)
    {
     // Send bytesto client     
      out.write(data,0,count);
     }
        System.out.println("CUSTOM LOG :: Response Body = " +
responseBody);
    }
    String responseFooters = client.getResponseFooters();
       if(responseFooters != null)
        out.write(responseFooters.getBytes());
       System.out.println("CUSTOM LOG :: Response Footers = " +
responseFooters);
------------------
 
Much Thanks,
Vish