Hi,

Hope this is the right forum for the question. 

I’m able to successfully upload a file via a website. Now I want to automate
this process by using a HttpClient to send a MultiPart post request. The
problem is that the requests kept getting rejected by the server due to
"corrupt form data” and that’s all the info I can get from the server.

That leaves me to compare the requests sent from the web browser (good) and
from my Eclipse (bad). I see some differences but can’t tell what might be
causing the issue. Hopefully the experts in this forum can offer some help.
Thanks.

Here’s the request sent from Eclipse (rejected):

Header part:
POST
/servlet/MultiHandlerServlet?handler=uploadfile&ftype=SingleTest&session=5FD7C716A553EDC777A344AE92CE3123
HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Authorization: Basic MDAwMTExNDQ0Njp0byQ4bWVybg==
Host: www.xxxxxxx.com
Cookie: $Version=0; JSESSIONID=D23D72FFB75E7EC13121441A171C5180; $Path=/
Content-Length: 469
Content-Type: multipart/form-data;
boundary=PoNK69pnchJKwVLDEQ-phInJ_mC8R6e95M7OP


Body part:
--PoNK69pnchJKwVLDEQ-phInJ_mC8R6e95M7OP
Content-Disposition: form-data; name="BulkSingleFlag"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

Single
--PoNK69pnchJKwVLDEQ-phInJ_mC8R6e95M7OP
Content-Disposition: form-data; name="file"; filename="testfile.xfd"
Content-Type: application/vnd.adobe.xfd+xml; charset=ISO-8859-1
Content-Transfer-Encoding: binary

this is a test file.

--PoNK69pnchJKwVLDEQ-phInJ_mC8R6e95M7OP-- 



Here’s the request sent from the browser (accepted)

Header part:
Host 
User-AgentMozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3)
Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)Accept
text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8Accept-Languageen-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Referer https://www.xxxxxxxx
Proxy-AuthorizationBasic Y2hlbndlYTpJYW1maWxlMA==

Body part:
Content-Type: multipart/form-data;
boundary=---------------------------41184676334
Content-Length: 651

-----------------------------41184676334
Content-Disposition: form-data; name="file"; filename="testfile.xfd"
Content-Type: application/vnd.adobe.xfd+xml

this is a test file.
-----------------------------41184676334
Content-Disposition: form-data; name="BulkSingleFlag"

Single
-----------------------------41184676334--


Any suggestions would be greatly appreciated. One thing I noticed is that
the browser sent the lines below in the beginning of the body and HttpClient
sent them as part of the header. Could that be a problem? If yes, how should
I fix the behavior?


Content-Type: multipart/form-data;
boundary=---------------------------41184676334
Content-Length: 651

Here's the related source code:

      PostMethod request = new PostMethod(uri);
      FilePart filePart = createFilePart(fileUpload);
      Part[] parts = {new StringPart("BulkSingleFlag", "Single"),
                        filePart};
 
      request.setRequestEntity(new MultipartRequestEntity(parts,
request.getParams()));
      int httpResponseCode = httpClient.executeMethod(request);

Thanks. 
-- 
View this message in context: 
http://www.nabble.com/HttpClient-MultiPart-file-upload-getting-rejected-tp25703852p25703852.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to