I write a webservice in django
if i use from terminal command like this
curl --dump-header - -H "Content-Type: application/json" -X PUT
-开发者_运维知识库-data '{"name": "Change","address": "/api/v1/user/1/"}'
http://localhost:8000/api/items/1/
How to write command it to Android request to webservice?
This should do it:
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 10000);
HttpConnectionParams.setSoTimeout(myParams, 10000);
HttpClient httpClient = new DefaultHttpClient(myParams);
HttpContext localContext = new BasicHttpContext();
HttpPut httpPut = new HttpPut("http://localhost:8000/api/items/1/");
httpPut.setHeader("Accept", "application/json");
httpPut.setHeader("Content-Type", "application/json");
String data = // put your JSON object here
tmp = new StringEntity(data, "UTF-8");
httpPut.setEntity(tmp);
response = httpClient.execute(httpPut, localContext);
Srting result = EntityUtils.toString(response.getEntity());
精彩评论