File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes HttpPost and byte[] on Android? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "HttpPost and byte[] on Android?" Watch "HttpPost and byte[] on Android?" New topic
Author

HttpPost and byte[] on Android?

Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Hello,

I am dealing with http post method on Android. I have successfully send simple string pairs using HttpClient and HttpPost class with the NameValuePair as entity. However now I want to send a simple array of bytes[]. Unfortunately the only entities I have found for the HttpPost class are the NameValuePair and FileEntity. However my byte[] is not from a file. Wirting it to a file and then sending by the FileEntity seems to be pointless and stupid. How can I send this array using default HttpClient and HttpPost class??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
HTTP works with character data, not binary data. The easiest may be to still use a NameValuePair, after converting the byte[] to a String via the android.util.Base64 class.


Ping & DNS - my free Android networking tools app
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Thank you. Since my data will still be base64 encoded this seems a good solution. However do I need to use the NameValuePair? I do not need to arrange the date in pairs - I just need to send the whole string...

I came upon another problem - in addition to a byte[] I also need to send a short[]. Can you also help with that problem?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Yes, you need to give it a name so that you can retrieve it in the servlet via getParameter - where you pass in the name.
 
jQuery in Action, 2nd edition
 
subject: HttpPost and byte[] on Android?