Send JSON object via HttpPost method

by Alok Kulkarni » Tue, 08 Sep 2009 21:19:18 GMT

Sponsored Links
 Any answers ??


Send JSON object via HttpPost method

by Wayne Wenthin » Wed, 09 Sep 2009 05:39:03 GMT

 A snippet for what I do...
public HttpResponse updateGirl(String url, Pawn girl, int pawnID) {
HttpClient httpclient = new DefaultHttpClient();
HttpPut httpput = new HttpPut(url);

// Execute the request

try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
nameValuePairs.add(new BasicNameValuePair("id", Integer
......  Many nameValuePairs later.....

httpput.setEntity(new UrlEncodedFormEntity(nameValuePairs,
 HttpResponse response = httpclient.execute(httpput);
return response;

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
return null;


Hope that helps.   I struggled with it for a couple of weeks before I found
a site that had a good source.

Writing code is one of few things
that teaches me I don't know everything.


Sponsored Links

Send JSON object via HttpPost method

by Alok Kulkarni » Wed, 09 Sep 2009 16:44:42 GMT

 ey Wayne, thanks a lot..
I have also got a solution parallely which i would like to post

URL url = new URL(serverURL);

// open the conncetion
HttpURLConnection connection =

// Let the run-time system (RTS) know that we want input.
// Let the RTS know that we want to do output
// No caching, we want the real thing
// set the content type property

// set request method
// create the post body to send
String content = credDevPair.toString();
Log.i("Request ====....... ",content);
DataOutputStream printout = new DataOutputStream (
connection.getOutputStream () );

// send the data
String output =
Log.i("Response 1....... ",output);
// A Simple JSONObject Creation
JSONObject json=new JSONObject(output);


// A Simple JSONObject Parsing
JSONArray nameArray=json.names();
JSONArray valArray=json.toJSONArray(nameArray);
for(int i=0; i<valArray.length() ;i++)


//BufferedReader input = new BufferedReader ( new
InputStreamReader(connection.getInputStream()) );

}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
}catch (IOException e) {
// TODO Auto-generated catch block

}catch(Exception ex)


private static String convertStreamToString(InputStream is) {
* To convert the InputStream to String we use the
* method. We iterate until the BufferedReader return null which
* there's no more data to read. Each line will appended to a
* and returned as String.
BufferedReader reader = new BufferedReader(new
StringBuilder sb = new StringBuilder();

String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
} catch (IOException e) {
} finally {
try {
} catch (IOException e) {

return sb.toString();

On Wed, Sep 9, 2009 at 3:08 AM, Wayn

Send JSON object via HttpPost method

by Wayne Wenthin » Thu, 10 Sep 2009 08:58:06 GMT

 ep that is what I vaguely based mine on.   I recognize the Praeda line.   I
had to modify mine because I was not sending back an array of json objects
but a specific one that I handle based on the ID on the backend with ruby.

On Wed, Sep 9, 2009 at 1:43 AM, Alok Kulkarni <> wrote:

Writing code is one of few things
that teaches me I don't know everything.


Send JSON object via HttpPost method

by Alok Kulkarni » Thu, 10 Sep 2009 13:28:31 GMT

 k.. ya i had taken that code part from the forum itself. :)

On Thu, Sep 10, 2009 at 6:27 AM, Wayne Wenthin <> wrote:


Other Threads

1. Android setBackgroundResource release memory?

Hi, I have 2 quiet big Animations each 50pics a 20kb
Both defined as Animations .xml

One I let start from the beginning and the second after a button

    //Start immediatly
                        rocketAnimation = (AnimationDrawable)

    //Start after button click
                        rocketAnimation = (AnimationDrawable)

It works fine, till i hit the button and assign the second anim to my

    08-22 14:56:03.886: DEBUG/AndroidRuntime(1541): Shutting down VM
    08-22 14:56:03.886: WARN/dalvikvm(1541): threadid=3: thread
exiting with uncaught exception (group=0x4001da28)
    08-22 14:56:03.886: ERROR/AndroidRuntime(1541): Uncaught handler:
thread main exiting due to uncaught exception
    08-22 14:56:04.096: ERROR/AndroidRuntime(1541):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    08-22 14:56:04.096: ERROR/AndroidRuntime(1541):     at Method)

It looks definitly that each animation for itself is fine (i could
even set anim2 at the autostart). but BOTH will exceed the memory.

Btw. on my Nexus One it works perfect. Where it fails is on G1 1.6
(even in Simulator).

So HOW would I release anim1 first before I assign anim2 ??



2. Unable to build android image as described in the porting guide...

I have followed the instructions in the porting guide (http:// I have set up everything as
described there and always end up with a failed build...

The error message I get is:
Install: out/target/product/emh-board-release1/system/app/
make: *** No rule to make target `out/target/product/emh-board-
release1/obj/lib/', needed by `out/target/product/emh-board-
release1/obj/SHARED_LIBRARIES/libaudioflinger_intermediates/LINKED/'.  Stop.

I have fetched the external/alsa-lib, external/alsa-utils/ and
hardware/alsa_sound and this didn't help... Any ideas what might be
going wrong... Just for the record, I'm using the latest code.


3. Programmatically expanding / collapsing items of an ExpandableListView

4. Submit a Picture to server

5. Cannot use the sdcard while connected by means of USB - problems testing

6. one problem regarding sdk addon

7. Android wifi power mode - kernel or API?