Skip to content

Instantly share code, notes, and snippets.

@guilhermecarvalhocarneiro
Created March 12, 2014 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermecarvalhocarneiro/9506197 to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/9506197 to your computer and use it in GitHub Desktop.
HttpPost Android para API DjangoRestFramework
JSONObject jsonobject = new JSONObject();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://*******/apirestfull/******/");
httppost.setHeader("Content-Type","application/json");
httppost.setHeader("Authentication", "Token 0d0c898a*****e8bd");
jsonobject.put("nome", "Guilherme");
jsonobject.put("pais", "Brasil");
jsonobject.put("chave", Key);
httppost.setEntity(new StringEntity(jsonobject.toString(), "UTF-8"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.i("Resposta", response.getStatusLine().toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment