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 Ham MI-EN Oliver Rennert <ol...@kuehne-nagel.com> on 2005/02/08 23:01:40 UTC

Set Content-length in mulitpart headers

Hello httpclient users

I am posting files to a server with a MultipartRequestEntity.

The result looks like this:
--FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt
Content-Disposition: form-data; name="prefix"
Content-Type: application/x-www-form-urlencoded; charset=US-ASCII

AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&ResponseType=application/x-ups-pld&
VersionNumber=V4R1&UserId=USER&Password=PASSWORD
--FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt
Content-Disposition: form-data; name="testpld0200.txt";
filename="testpld0200.txt"
Content-Type: application/x-ups-binary; charset=ISO-8859-1

020094                                  2005012700000590210000800
000000001*AA590210
--FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt--


But I also need the client to create a Content-length header for every part.
I browsed already through the source code and noticed that the Content-length
will only be created if the TransferEncoding is null and the content is not
chunked.

For this reason I included the following into my code:
  post.setContentChunked(false);
  stringPart.setTransferEncoding(null);
  filePart.setTransferEncoding(null);


Who knows how to add the ContentLength Header?


Kind Regards,
Oliver Rennert


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


Re: AW: Set Content-length in mulitpart headers

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2005-02-09 at 22:40 +0100, Ham MI-EN Oliver Rennert wrote:
> Oleg
> 
> RFC2616, section 4.4 states that "Messages MUST NOT
> include both a Content-Length header field and a non-
> identity transfer-coding. If the message does include a
> non- identity transfer-coding, the Content-Length MUST
> be ignored."

Again, you are confusing HTTP content with MIME content. These are not
the same things. RFC 2616 defines the HTTP/1.1 protocol

> 
> That is why I set filePart.setTransferEncoding(null).

Whereas the multipart content is defined in RFC 1521 and RFC 1522.

Hope that clarifies things a little

Oleg


> 
> Unfortunately the server I send the data to requires the length to be sent.
> 
> The question is: How can I configure the client to add this request header?
> 
> Thank you for your help.
> 
> Oliver
> 
> 
> > -----Ursprüngliche Nachricht-----
> > Von:
> > httpclient-user-return-344-oliver.rennert=kuehne-nagel.com@jakarta.apach
> > e.org
> > [mailto:httpclient-user-return-344-oliver.rennert=kuehne-nagel.com@jakar
> > ta.apache.org]Im Auftrag von Oleg Kalnichevski
> > Gesendet: Mittwoch, 9. Februar 2005 22:22
> > An: HttpClient User Discussion
> > Betreff: Re: Set Content-length in mulitpart headers
> >
> >
> > Oliver,
> >
> > You are confusing 'Transfer-Encoding' of the HTTP content and that of a
> > MIME part within a multipart/form-data encoded content.
> >
> > It's been a while since I looked at the spec but if my memory does not
> > fail me, Content-length was not required for a MIME part.
> >
> > Oleg
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 


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


AW: Set Content-length in mulitpart headers

Posted by Ham MI-EN Oliver Rennert <ol...@kuehne-nagel.com>.
Oleg

RFC2616, section 4.4 states that "Messages MUST NOT
include both a Content-Length header field and a non-
identity transfer-coding. If the message does include a
non- identity transfer-coding, the Content-Length MUST
be ignored."

That is why I set filePart.setTransferEncoding(null).

Unfortunately the server I send the data to requires the length to be sent.

The question is: How can I configure the client to add this request header?

Thank you for your help.

Oliver


> -----Ursprüngliche Nachricht-----
> Von:
> httpclient-user-return-344-oliver.rennert=kuehne-nagel.com@jakarta.apach
> e.org
> [mailto:httpclient-user-return-344-oliver.rennert=kuehne-nagel.com@jakar
> ta.apache.org]Im Auftrag von Oleg Kalnichevski
> Gesendet: Mittwoch, 9. Februar 2005 22:22
> An: HttpClient User Discussion
> Betreff: Re: Set Content-length in mulitpart headers
>
>
> Oliver,
>
> You are confusing 'Transfer-Encoding' of the HTTP content and that of a
> MIME part within a multipart/form-data encoded content.
>
> It's been a while since I looked at the spec but if my memory does not
> fail me, Content-length was not required for a MIME part.
>
> Oleg
>


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


Re: Set Content-length in mulitpart headers

Posted by Oleg Kalnichevski <ol...@apache.org>.
Oliver,

You are confusing 'Transfer-Encoding' of the HTTP content and that of a
MIME part within a multipart/form-data encoded content. 

It's been a while since I looked at the spec but if my memory does not
fail me, Content-length was not required for a MIME part.

Oleg

On Tue, 2005-02-08 at 23:01 +0100, Ham MI-EN Oliver Rennert wrote:
> Hello httpclient users
> 
> I am posting files to a server with a MultipartRequestEntity.
> 
> The result looks like this:
> --FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt
> Content-Disposition: form-data; name="prefix"
> Content-Type: application/x-www-form-urlencoded; charset=US-ASCII
> 
> AppVersion=1.0&AcceptUPSLicenseAgreement=Yes&ResponseType=application/x-ups-pld&
> VersionNumber=V4R1&UserId=USER&Password=PASSWORD
> --FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt
> Content-Disposition: form-data; name="testpld0200.txt";
> filename="testpld0200.txt"
> Content-Type: application/x-ups-binary; charset=ISO-8859-1
> 
> 020094                                  2005012700000590210000800
> 000000001*AA590210
> --FZU0uEJyLTvOZGiw2Wsmm5Bl7a330uHLv5YKIKt--
> 
> 
> But I also need the client to create a Content-length header for every part.
> I browsed already through the source code and noticed that the Content-length
> will only be created if the TransferEncoding is null and the content is not
> chunked.
> 
> For this reason I included the following into my code:
>   post.setContentChunked(false);
>   stringPart.setTransferEncoding(null);
>   filePart.setTransferEncoding(null);
> 
> 
> Who knows how to add the ContentLength Header?
> 
> 
> Kind Regards,
> Oliver Rennert
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 


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