[
https://issues.apache.org/jira/browse/HTTPCLIENT-971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12893220#action_12893220
]
Dominik Dorn commented on HTTPCLIENT-971:
-----------------------------------------
Ok. I called one of the devs of the site and they sent me this debug trace from
there server.
Processing Main::SessionsController#create (for 188.22.164.99 at 2010-07-28
17:34:46) [POST]
Parameters: {"user_session"=>{"email"=>"[email protected]",
"password"=>"[FILTERED]"}, "subdomains"=>["www", ""],
"controller"=>"main/sessions", "action"=>"create"}
Redirected to http://letsannotate.com/documents
Completed in 4ms (DB: 1) | 302 Found [http://letsannotate.com/login]
Processing Main::DocumentsController#new (for 188.22.164.99 at 2010-07-28
17:34:46) [GET]
Parameters: {"subdomains"=>["www", ""], "controller"=>"main/documents",
"action"=>"new"}
Rendering template within layouts/main
Rendering main/documents/new
Completed in 6ms (View: 3, DB: 0) | 200 OK
[http://letsannotate.com/documents/new]
Processing Main::DocumentsController#create (for 188.22.164.99 at 2010-07-28
17:34:47) [POST]
Parameters:
{"authenticity_token"=>#<File:/tmp/RackMultipart20100728-16726-w5dd6a>,
"document"=>{"pdf_file"=>#<File:/tmp/RackMultipart20100728-16726-1gen41o>,
"progress_token"=>#<File:/tmp/RackMultipart20100728-16726-18kmgov>},
"commit"=>#<File:/tmp/RackMultipart20100728-16726-mujixf>,
"X-Progress-ID"=>"931489207c8b012d4400406186cbf281", "subdomains"=>["www", ""],
"controller"=>"main/documents", "action"=>"create"}
ActionController::InvalidAuthenticityToken
(ActionController::InvalidAuthenticityToken):
/usr/local/rvm/rubies/ruby-1.9.2-rc1/lib/ruby/gems/1.9.1/gems/hoptoad_notifier-2.3.0/lib/hoptoad_notifier/rack.rb:27:in
`call'
<internal:prelude>:10:in `synchronize'
/usr/local/rvm/gems/ruby-1.9.2-rc1/gems/passenger-2.2.15/lib/phusion_passenger/rack/request_handler.rb:92:in
`process_request'
/usr/local/rvm/gems/ruby-1.9.2-rc1/gems/passenger-2.2.15/lib/phusion_passenger/abstract_request_handler.rb:207:in
`main_loop'
/usr/local/rvm/gems/ruby-1.9.2-rc1/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.rb:441:in
`start_request_handler'
/usr/local/rvm/gems/ruby-1.9.2-rc1/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.
http://pastie.org/private/pl7mfycdhjwkm9gsgicqfw
so actually the normal input fields (progress_token, commit, etc.) get treated
as files by Ruby on Rails.
I assume this is because the StringBody appends Content-Type and Character
encoding.
<code>
Content-Disposition: form-data; name="authenticity_token"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
wPI5PtwxOSOnRzJPPWylV8ad0eiV6eA6L6QkcL7+0fk=
</code>
It looks actually like a bug in Ruby on Rails to me.
However, I created my own Class implementing ContentBody which now works as
expected.
The code now looks like this:
<code>
MultipartEntity entity = new MultipartEntity();
HttpResponse response;
try{
entity.addPart("authenticity_token", new
PlainBody(token.getAuthenticityToken()));
entity.addPart("document[pdf_file]", new FileBody(file,
"application/download"));
entity.addPart("document[progress_token]", new
PlainBody(token.getProgressToken()));
entity.addPart("commit", new PlainBody("Upload"));
post.setEntity(entity);
</code>
and produces an equal trace like firefox and the others do.
So in short: Using the StringBody class in a multipart/form-data request may
make some servers think
an normal input field is a File because it contains the Content-Type and
Transfer-Encoding parts.
I know, you're already nerved by this request, but maybe you want to note this
somewhere in the
documentation or even include the attached file into the library.
> Multipart Post / FileUpload is missing necessary boundary header
> ----------------------------------------------------------------
>
> Key: HTTPCLIENT-971
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-971
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpMime
> Affects Versions: 4.0.1, 4.1 Alpha2
> Environment: Ubuntu 10, Java 6
> <dependency>
> <groupId>org.apache.httpcomponents</groupId>
> <artifactId>httpclient</artifactId>
> <!--<version>4.0.1</version>-->
> <version>4.1-alpha2</version>
> </dependency>
> <dependency>
> <groupId>org.apache.httpcomponents</groupId>
> <artifactId>httpmime</artifactId>
> <!--<version>4.0.1</version>-->
> <version>4.1-alpha2</version>
> </dependency>
> 4.0.1 and 4.1-alpha2 have this bug.
> Reporter: Dominik Dorn
> Priority: Minor
> Attachments: dump_firefox
>
> Original Estimate: 4h
> Remaining Estimate: 4h
>
> When doing a multipart post, with a code like this:
> <code>
> HttpPost post = new HttpPost("http://" + host + ":" + port + uploadUrl +
> token.getProgressToken());
> HttpContext context = new BasicHttpContext();
> CookieStore store = cred.getCookieStore();
> context.setAttribute(ClientContext.COOKIE_STORE, store);
> MultipartEntity entity = new MultipartEntity();
> HttpResponse response;
> try{
> entity.addPart("document[pdf_file]", new FileBody(file));
> entity.addPart("authenticity_token", new
> StringBody(token.getAuthenticityToken(), Charset.forName("UTF-8")));
> entity.addPart("document[progress_token]", new
> StringBody(token.getProgressToken(), Charset.forName("UTF-8")));
> post.setEntity(entity);
> HttpClient client = new DefaultHttpClient();
> response = client.execute(post, context);
> </code>
> The required initializing Header
> <code>
> Content-Type: multipart/form-data;
> boundary=---------------------------15590059519136285452113363602
> Content-Length: 38377
> -----------------------------15590059519136285452113363602
> Content-Disposition: form-data; name="authenticity_token"
> VkJ/mnCDmImYfEVT0zNFBvyyhihKSaUX5j7Vm7d0WUQ=
> </code>
> is missing.
> Instead it directly starts with
> <code>
> --gDRYDFqyzjuUrRL5No6B5wHN6BT5Ts2
> Content-Disposition: form-data; name="authenticity_token"
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> rvMzKRruVZaKX7JV+4Zpg7LWdxEuhq2hSgtaCIcSzCg=
> </code>
> The target server ( a rails one ) seems not to be able to understand this
> multipart upload.
> I think the correct place to fix is
> org.apache.http.entity.mime.MultipartEntity but I'm not sure where and how to
> do it.
> Please help.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]