Hi,
I've got a problem with uploading binary data using chunked transfer encoding. I always get HTTP 400 (bad_request) response from the server. I did tests on Jetty and Tomcat server with same result.
Here's a snippet of code on the client side.
-------------------------------------------------------------------------------------------
DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
config.getProperties().put(
ApacheHttpClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE, 0);
ApacheHttpClient client = ApacheHttpClient.create(config);
WebResource res = client.resource("
http://localhost:8080/repository/test/contents/save");
InputStream in = new FileInputStream(new File("c:/abc.JPG"));
BodyPart bp = new BodyPart(in,
MediaType.APPLICATION_OCTET_STREAM_TYPE);
MultiPart multiPartInput = new MultiPart().bodyPart(bp);
Builder builder = res.type(MultiPartMediaTypes.MULTIPART_MIXED);
ClientResponse response = builder.post(ClientResponse.class, multiPartInput);
--------------------------------------------------------------------------------
Here's the sent http request:
HEADERS:
(Request-Line):POST /repository/test/contents/save HTTP/1.1
Content-Type:multipart/mixed
User-Agent:Jakarta Commons-HttpClient/3.1
Host:localhost:8080
Transfer-Encoding:chunked
RESPONSE:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 971
Date: Tue, 16 Mar 2010 07:05:39 GMT
Connection: close
The request sent by the client was syntactically incorrect
Any idea what I'm doing incorrectly?
Environment:
jersey 1.1.4
jetty 2.0
tomcat 6.0
Thank you.
Best regards
Jaroslav