Setting content length of an HTTP POST request
===

I am trying to make a Http POST request using apache HTTP client. I am trying to copy contents of an HTTP POST request (received at my application) to another HTTP POST request (initiated from my application to another URL). Code is shown below:


    httpPost = new HttpPost(inputURL);
    // copy headers
    for (Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements();) {
          String headerName = e.nextElement().toString(); 
          httpPost.setHeader(headerName, request.getHeader(headerName));
    }
    			
    BufferedInputStream clientToProxyBuf = new BufferedInputStream(request.getInputStream());
    BasicHttpEntity basicHttpEntity = new BasicHttpEntity();
    basicHttpEntity.setContent(clientToProxyBuf);
    basicHttpEntity.setContentLength(clientToProxyBuf.available());
    			
    httpPost.setEntity(basicHttpEntity);
    
    HttpResponse responseFromWeb = httpclient.execute(httpPost);

Basically, I am trying to implement a proxy application which will get a url as parameter, froward the request to the URL and then serve pages etc in custom look and feel. 

Here `request` is HttpServletRequest. I am facing problem in setting content length. Through debugging I found out that `clientToProxyBuf.available()` is not giving me correct length of input stream. Am I doing it wrong? Is there any other way to achieve it?