• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Base64 encoded file as POST request not working correctly.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still waiting for reply!
 
Marshal
Posts: 67431
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Harvinder Kotli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic