I'm building an Android client for a web service that accepts POST data. We're standing on the fence which format to choose for the POST data. According to me, the easiest way is to send it in UrlEncoded format but server side developer thinks JSON is better.
What are the pros and cons of using UrlEncoded / jsonEncoded / bsonEncoded format?
I would avoid xmlencoded data, but what about the others?
The answer to your question greatly depends on what kind of data you're going to send. If your data is mostly string values, numbers and the like, probably JSON would be your best solution.
Avoid url-encoded data, use MultiPart instead -- it takes a bit more work, but it's more secure (url-encoded data it's visible in the server logs) and you may send large files (images?) easily.
If you are sending maps (set of key-value pairs) and arrays, JSON is probably the easiest to work with from a developer standpoint on both client and server. If you need to optimize instead on use bandwidth usage for large set of non-media data, protobuf works well.
Related
I was wondering if there are some commonly used techniques for synchronizing an app with a server? I have looked at the socket-framework and maybe some http? I am thinking for instance when making a game or a grocery list, any developers out there who want to share?
I would say that the most common method is to send client data via HTTP POST using SSL/TLS encryption. The data can be sent in any format, but generally it is structured as a JSON or XML message.
The hardest part is that you need some form of authentication in order to identify the user and update/sync the correct information on the server database in a secure manner. Have a look at this article for some basic concepts.
In android, you can use the excellent Google Gson library to convert Java object to/from JSON objects.
Http communication can be performed via the Android API methods.
I write app on android which will need to exchange xml data with http server. I wonder what would be the better approach. Send whole file via POST or maybe get all text from file put it on String and then send this String via POST. Is there will be some difference? If yes what is better option?
I would strongly recommend using POST. While sending the file content using GET is theoretically possibly, in some cases you may encounter problems when using URLs over 2000 characters in length. RFC imposes no strict limit, however some clients and servers impose their own limit. Look at this question for more details on this.
With POST this wouldn't apply and you can send (almost) any size data. To send the file, you would still need to read the content of the file and send it as POST parameter though. Again, in reality, most servers will not accept more than just below 2GB, but that's a separate issue.
What are the best ways to connect site and show it's data on an android application ? Also does I have to create anything on server where the site is for using JSON ? I am new to programming web android application's, though I searched a lot I didn't find anything which would explain me straight to the point.
You're on the solid ground starting out using JSON as the interchange between the two.
Alot of popular mobile apps like Twitter and Foursquare have restful APIs set up to interact with their mobile clients by exchanging HTTP requests that contain data formatted as JSON. Most of the communication between the two can be accomplished with HTTP requests using the standard GET and POST methods.
A good place to start would be setting up some server endpoints that output this data and then setting up your android app to request and parse this data just like a browser would. You just need to set the appropriate mimetypes on your server end (application/json).
Most modern server-side languages have implemented modules/functions that can take their native data structures and approximate them in serialized JSON (PHP's json_encode(), python's json.dumps() etc) These can be used to output data from within the app or database to your mobile client where it can be interpreted and used in the Java environment there.
To pass back JSON you need to set the mime type (http://stackoverflow.com/questions/477816/the-right-json-content-type), which is application/json.
If you are passing back JSON or XML then the client just needs to make the appropriate http call, most likely GET, perhaps POST, to actually retrieve the information.
You can use something like this as a starting point:
http://lukencode.com/2010/04/27/calling-web-services-in-android-using-httpclient/
The title almost says it all.
I'm building an Android App to collect data on sites. The data is stored in a sqlite database on the unit.
I'd like to transmit them to a web server over wifi.
The data is to be stored in sql form and analysed on the web server, then graphed on a web page.
I though about making a csv and send it to a php page that would parse it and write it to the server sql database.
I saw alson json, but must read more about it.
What are the best options to have the data transfered with integrity ?
Thanks a lot
I would recommend using JSON for a couple reasons:
It is human readable.
There are nice libraries for JSON-Object Mapping, such as Jackson or GSON.
There are JSONObject/JSONArray classes that are a part of Android that are easy to use.
As an additional option you can use Google's protocol buffers. With protobuf you have to include an additional library and write your data in a specific message format, but you gain an automatically generated library with getter/setter methods and the data is sent in binary form. All you have to do on either end is send/receive the number of bytes of the message and then write/read the message itself; the library takes care of populating all of your instance variables.
Of course this depends on what language you are using on the server, as you have to use a protobuf library there as well; but it would appear that there are many different language bindings, including for PHP.
I'm writing an app that will periodically send information out to a remote server, and then get relevant information about other users from that server back to the local database. What's the best way to handle sending out this info (i.e.: XML or binary) and writing it to the remote server.
Also, how can I assure that, when 500+ users' data get's to the server or FTP (or better alternative?) at once, the appropriate fields gets overwritten or added, without skipping any or overwriting the entire thing? Thanks for the help.
i was looking for that answer too and i found some nice tutorials. Unfortenly they are not in english, but you can understand a princip.
This (http://vimeo.com/29332913) is the forth video of tutorials. Just click on authors name and start 3 tutorials before.
Hope it will help you XD
Janez
Have you considered JSON? FTP is generally a solution when it comes to binary data (large files, etc.), however I assume you want to exchange data that contains information in a textual format, so for a website HTTP will be a good way (the best way depends entirely on your server setup, your data format and model).
I have to add, that YAML is also a very nice data format tool if you are using Ruby frameworks, which I prefer over JSON (personal experience).