Java – how to set the main body of httpput on Android? (do not add Library)
•
Java
I want to upload some data from the android app to pachube
[update: for those who read this in 2013, "pachube" became "Cosmo" and is now "xiely"
This hurl takes documentation as an example
How to achieve this goal through Android's httpput (or httppost)?
I really don't want to add any extra libraries because I want to keep the application as small as possible
I already have a jsonobject that contains my data
Solution
This is some pseudo code Please note that you should not send the form URL encoded data in the put request, because it may destroy the server-side OAuth (if used):
HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(url); put.addHeader("Content-Type","application/json"); put.addHeader("Accept","application/json"); put.setEntity(new StringEntity(jsonObj.writeValue())); HttpResponse response = client.execute(put);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码