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>(
39);
nameValuePairs.add(new BasicNameValuePair("id", Integer
.toString(pawnID)));
......  Many nameValuePairs later.....


httpput.addHeader("Content-Type",
"application/x-www-form-urlencoded");
httpput.setEntity(new UrlEncodedFormEntity(nameValuePairs,
HTTP.UTF_8));
 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
e.printStackTrace();
}
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 =
(HttpURLConnection)url.openConnection();

// Let the run-time system (RTS) know that we want input.
connection.setDoInput(true);
// Let the RTS know that we want to do output
connection.setDoOutput(true);
// No caching, we want the real thing
connection.setUseCaches(false);
// set the content type property
connection.setRequestProperty("Content-type",strContenttype);

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

// send the data
printout.writeBytes(content);
printout.flush();
printout.close();
String output =
convertStreamToString(connection.getInputStream());
Log.i("Response 1....... ",output);
// A Simple JSONObject Creation
JSONObject json=new JSONObject(output);

Log.i("Praeda","<jsonobject>\n"+json.toString()+"\n</jsonobject>");

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

Log.i("Praeda","<jsonname"+i+">\n"+nameArray.getString(i)+"\n</jsonname"+i+">\n"

+"<jsonvalue"+i+">\n"+valArray.getString(i)+"\n</jsonvalue"+i+">");
}
//BufferedReader input = new BufferedReader ( new
InputStreamReader(connection.getInputStream()) );

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

}catch(Exception ex)
{

}

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

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

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 <kulsu...@gmail.com> 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 <wa...@fuligin.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to take a picture using the Camera App and have it NOT appear in the Gallery?

Hi All,

Thanks for all your help on my past questions.  I have another one for
you:

How to take a picture using the Camera App and have it NOT appear in
the Gallery?

Here is what I have so far:


                                Time time = new Time();
                                time.setToNow();
                                File dir = new
File(Environment.getExternalStorageDirectory().toString() +
BusinessRules.IMAGE_PATH);
                                if (!dir.exists()) {
                                        dir.mkdirs();
                                }
                                String fileName = time.format("%Y%m%d%H%M%S") + 
".jpg";
                                File file = new File(dir, fileName);
                                try {
                                        file.createNewFile();
                                        ContentValues values = new 
ContentValues();
                                        values.put(Media.TITLE, fileName);
                                        values.put(Media.MIME_TYPE, 
"image/jpeg");
                                        values.put(Media.DATA, 
file.getAbsolutePath());
                                        values.put(Media.IS_PRIVATE, 1);
                                        Uri uri = 
getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);
                                        startActivityForResult(new
Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
uri), 0);
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }


I have tried specifying the Media.IS_PRIVATE flag but to no avail.

Any help is most appreciated!!

-- 

2. V4L2 problem

hello everyone ,recently i met a problem on android porting camera.
my board kernel is 2.6.24.7,and my android is eclair. when i insert my
usbcamera,it found a video0 in the /dev. and i click the application
camera.it just show 8 different colourful bars roll again and
again.like this :white ,black,red ,blue ,yellow.........
so , i use a capture_test in this thread:http://groups.google.ca/group/
rowboat/browse_thread/thread/3ad333d91f1bf0c0/ff6ee795ea30be4f.
when i input :capture_test,it shows:
# capture_test
============================================
Querying supported frame sizes

Image format: 4:2:2, packed, YUYV
============================================
32 Frames rendered, 0.330421 FPS
64 Frames rendered, 33.332985 FPS
96 Frames rendered, 33.323303 FPS
128 Frames rendered, 31.520634 FPS
160 Frames rendered, 32.325291 FPS
192 Frames rendered, 33.333019 FPS
224 Frames rendered, 33.334133 FPS
256 Frames rendered, 33.333576 FPS
288 Frames rendered, 33.332050 FPS
vivi/0: [c4e2fb00/0] timeout
vivi/0: [c4e2f780/1] timeout
vivi/0: [c4e2f580/2] timeout
vivi/0: [c4e2f000/3] timeout

and  the board screen show something like this:8 differnet colourfull
bars roll again and again :red black white yello blue........
what  about your board screen.is there some picture from usbcamera?and
i guess my kernel menuconfig is not perfect on the multimedia,
so can you give me some advice.
thank a lot

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Question regarding Message object

4. audio buffer problem in cupcake

5. Android Market Licensing intermittently fails

6. what is internalResolveIntent ?

7. Using newer wallpaer them on older Android version