File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Base64 encoded file as POST request not working correctly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Base64 encoded file as POST request not working correctly." Watch "Base64 encoded file as POST request not working correctly." New topic
Author

Base64 encoded file as POST request not working correctly.

Harvinder Kotli
Greenhorn

Joined: Dec 26, 2008
Posts: 5
Hi,

In my web application, client sends XML request.This XML request contains a File (mostly Image and audio) data which is Base64 encoded.
What my application does is parse the XML get the encoded file content and after decoding the file content back to binary,
file is saved on local file system.

If i send POST request from a JSP page it is working fine, but its not working if I send a custom POST request from java class.
Server does receive file but file is corrupted.However simple text file is not corrupted in any of the above clients.

Following is request headers:
For JSP

accept-language --> en-us
content-type --> application/x-www-form-urlencoded
accept-encoding --> gzip, deflate

user-agent --> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MS-RTC LM 8; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322)

host --> localhost:8080
content-length --> 5096
connection --> Keep-Alive
cache-control --> no-cache
cookie value JSESSIONID=EE61EA4CCFAE6A3E05F0877372E012A7

For Request sent from Java class:

content-type --> application/x-www-form-urlencoded
accept-encoding --> gzip, deflate
content-length --> 4765
cache-control --> no-cache
pragma --> no-cache
user-agent --> Java/1.5.0_13
host --> localhost:8080
accept --> text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
connection --> keep-alive


Server is Tomcat 5.5
From above data it is clear that content length is different, but in logs I see entire XML is received on the server.




Harvinder Kotli
Greenhorn

Joined: Dec 26, 2008
Posts: 5
still waiting for reply!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

After 2 hours, you post a bump? Please show some patience; it is no one's job to answer your questions. And being rude won't exactly make people want to answer them.

Please read this for more information.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harvinder Kotli
Greenhorn

Joined: Dec 26, 2008
Posts: 5
Figured out the problem, In my custom client I am setting Content-Type to "application/x-www-form-urlencoded "
but request parameters are not URL Encoded automatically like it is done by browser.
URLEncoding the request parameters worked.

The above solution was not preferable because it requires two encodings first Binary to base64 and second URLEncoding the entire request.

So set Content-Type to "multipart/form-data", where only binary to Base64 encoding is required.



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Base64 encoded file as POST request not working correctly.