Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpClient MultiPart file upload getting rejected

843790Oct 1 2009 — edited Oct 5 2009
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:
{color:#0000ff}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
{color}

Body part:
{color:#0000ff}--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.
{color}
{color:#0000ff}--PoNK69pnchJKwVLDEQ-phInJ_mC8R6e95M7OP--{color}



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

Header part:
{color:#0000ff}Host {color}[{color:#0000ff}www.xxxxxx{color}|http://www.xxxxxx/]
{color:#0000ff}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=={color}

Body part:
{color:#0000ff}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--
{color}

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?


{color:#0000ff}Content-Type: multipart/form-data; boundary=---------------------------41184676334
Content-Length: 651{color}


Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2009
Added on Oct 1 2009
6 comments
634 views