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 Da...@thomson.com on 2007/05/02 19:18:55 UTC
Multpart Post Problem
Greetings,
I am creating a Post method using a MultipartRequestEntity that is used
for a login request to an https site (The login form on the page uses
multipart/form-data even though there is only form data involved). I'm
using a Part array with StringParts for the login and password. The
problem is that the response code is 200 but the login fails (login
and/or password is incorrect), even though the information is correct.
If I remove one of the StringPart objects in the Part array, the
response page indicates that both login and pw are required, so it looks
like the server is able to parse the request, but somehow the form data
is not handled correctly. Could this be some sort of Content-Length or
boundary problem?
I've been struggling with this for a few days now and can't find
anything in the archives. Any help would be appreciated.
Thanks,
Dave
RE: Multpart Post Problem
Posted by Da...@thomson.com.
Thanks, Roland. We finally solved our issue by excluding the content
type and transfer encoding headers from the request. I'm not exactly
sure why one works and the other doesn't, but here is the solution:
//Using this fails
Part[] parts = {
new StringPart("login", login),
new StringPart("password", password)
};
//This works
StringPart part1 = new StringPart("login", login);
part1.setContentType(null);
part1.setTransferEncoding(null);
StringPart part2 = new StringPart("password", password);
part2.setContentType(null);
part2.setTransferEncoding(null);
Part[] parts = { part1, part2 };
//create the request entity
MultipartRequestEntity mre = new MultipartRequestEntity(parts,
postMethod.getParams());
postMethod.setRequestEntity(mre);
Thanks,
Dave
-----Original Message-----
From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
Sent: Thursday, May 03, 2007 2:50 AM
To: HttpClient User Discussion
Subject: Re: Multpart Post Problem
Hello Dave,
have a look at the Primer, it explains a lot of the things you should
look for:
http://wiki.apache.org/jakarta-httpclient/ForAbsoluteBeginners
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Multpart Post Problem
Posted by Roland Weber <RO...@de.ibm.com>.
Hello Dave,
have a look at the Primer, it explains a lot of
the things you should look for:
http://wiki.apache.org/jakarta-httpclient/ForAbsoluteBeginners
hope that helps,
Roland