commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Sutton <adrian.sut...@ephox.com>
Subject RE: [httpclient] HTTP Post with 0 content-length
Date Fri, 07 Feb 2003 00:58:54 GMT
Hi,
The answer to this is very likely to depend on the version of HttpClient
you're using.  I've included a couple of possible theories below, but if
they don't help it would be good if you could provide me with the following:

1. The version of HttpClient you're using.
2. A simple, complete test case showing the problem you're having.
(Something that I can compile and run to see the problem is best)

---- Theory 1 -----
I believe you are getting an IOException when trying to read one of the
parameters you're supplying.  The exception is (wrongly, very very wrongly)
being silently "handled" by HttpClient.  HttpClient somewhat unfortunately
handles it by setting the requestContentLength to 0 and setting the
requestBody to null, so the contentlength is zero and there really is no
data sent.

The silent handling of the exception was changed to report an error in the
last few days so it may be worth grabbing a nightly build and trying your
application with that to see what the error message is.  

---- Theory 2 -----
In versions of HttpClient older than a couple of weeks, the
CONTENT_LENGTH_AUTO setting may (or may not) have only worked with
InputStreams and not name value pairs, thus if you removed the call to
setRequestContentLength method it may work better.

---- Theory 3 -----
It's fairly unlikely that you haven't checked this but... the array of name
value pair's isn't empty right? :)


-------------------

I think I really need to know the version of HttpClient your using though
because the code's changed fairly dramatically and it would help if I could
look at the actual code that's running and not just try to guess at it. :)

Hope some of that helps anyway,

Adrian Sutton, Software Engineer
Ephox Corporation
www.ephox.com


-----Original Message-----
From: Ian [mailto:ian@bashford.net]
Sent: Friday, 7 February 2003 12:17 AM
To: commons-user@jakarta.apache.org
Subject: [httpclient] HTTP Post with 0 content-length


Hi all,

I seem to be successfully sending an HTTP Post but with one problem.
The content-length header is set to zero and nothing I do can make it non
zero.
A sniffer reveals the data is sent but as the content-length header is zero,
the servlet 
at the other end treats it as no content !!!

My code looks like this

state = new HttpState();
postMethod = new PostMethod("http://" + URL);

//  Loop to add request Headers {
    postMethod.addRequestHeader(headerName,headerValue );
}

postMethod.setFollowRedirects(false);

NameValuePair[] nvp = new NameValuePair [numParameters];

// Generate an array of NameValuePairs
postMethod.addParameters(nvp);

// Next line is default but .....
postMethod.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO);

// Get Connection from Connection Manager

responseCode = method.execute(state, conn);

// Process response


The servlet receives
Headers
  accept:text/*, image/jpeg, image/png, image/*, */*
  accept-charset:iso-8859-1, utf-8;q=0.5, *;q=0.5
  accept-encoding:x-gzip, gzip, identity
  accept-language:en
  content-length:0
  content-type:application/x-www-form-urlencoded
  host:eris2
  user-agent:Mozilla/5.0 (compatible; Konqueror/3; Linux)
Parameters
  0oc:106
Posted
  0 bytes sent

Nothing I do changes the content-length from zero !!
Can anyone help ?

-- 

Thanks

Ian

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message