I've got an android application that I'm attempting to use to pass some data to a webservice using HTTPGet. If I just construct the string using the JSONArray.toString() method, I end up with a URL that looks something like the following:
http://xxx.xx.xxx.xx/api?method=upload&args[deviceID]=123456789&args[data]=["{element1=93295352, element2=235235, element3=3523523}","{element1=93295352, element2=235235, element3=3523523}"]
This doesn't work because of the spaces and quotation marks in the URL. If I attampt to do something like the following:
JSONArray ja = new JSONArray();
// Add Data to JSONArray
String s = ja.toString();
// Add array to StringBuilder url
HTTPGet httpget = new HTTPGet(UrlEncoder.encode(url.toString()));
I get an error thrown because the entire URL gets encoded and ends up like this:
http%3A%2F%2Fxxx.xx.xxx.xx%2Fapi%3Fmethod%3Dupload%26args%5BdeviceID%5D%3D123456879%26args%5Bdata%5D%3D%5B%22%7Belement1%3D915156028000%2C+element2%3D1651651%2C+element3%3D489461%7D%22%2C%22
Obviously, this isn't what I'm looking for, and there's got to be a better solution than searching/replacing all the necessary characters in the JSONArray portion of that url, though I suppose doing it that way wouldn't be a huge hassle since I'm only worried about quotation and space characters.
Note that manually pasting this into my browser returned the results I expect:
http://xxx.xx.xxx.xx/api?method=upload&args[deviceID]=123456789&args[data]=[%22{element1=915156028000,%20element2=0.0,%20element3=2.297444}%22,%22{element1=915156055000,%20element2=0.0,%20element3=2.2974419999999998}%22]