Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public class post extends AsyncTask<String, Void, String> {
  2.  
  3.  
  4. protected void onPreExecute() {
  5.  
  6. }
  7.  
  8.  
  9. protected String doInBackground(String... arg0) {
  10.  
  11.  
  12. try {
  13.  
  14.  
  15. URL url = new URL("http://192.168.1.207/api/v2/xxxx/xxxx/cad_livro?fields=vl_pago%2Cvl_oferta%2Cid_user%2Cid_liv&filter=id_user%20%3D%20" + teste);
  16.  
  17. JSONObject postDataParams = new JSONObject();
  18.  
  19. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  20.  
  21. conn.setRequestProperty("Content-type", "application/json");
  22. conn.setRequestMethod("POST");
  23. conn.setReadTimeout(15000 /* milliseconds */);
  24. conn.setConnectTimeout(15000 /* milliseconds */);
  25. conn.setDoInput(true);
  26. conn.setDoOutput(true);
  27.  
  28. //ContentValues post = new ContentValues();
  29.  
  30. postDataParams.put("id_user_comp", idUser);
  31. postDataParams.put("vl_pago", mVl_anun);
  32. postDataParams.put("id_liv", id_livro);
  33.  
  34. Log.e("resource", postDataParams.toString());
  35.  
  36.  
  37. JSONObject resource = new JSONObject();
  38. JSONArray array = new JSONArray();
  39. array.put(postDataParams);
  40. resource.put("resource", array);
  41.  
  42. // System.out.println("Resposta do server: "+ resource.toString());
  43.  
  44.  
  45. conn.connect();
  46. OutputStream os = conn.getOutputStream();
  47. BufferedWriter writer = new BufferedWriter(
  48. new OutputStreamWriter(os, "UTF-8"));
  49. //writer.write(getPostDataString(postDataParams));
  50. writer.write(resource.toString());
  51.  
  52. writer.flush();
  53. writer.close();
  54. os.close();
  55.  
  56.  
  57. int responseCode = conn.getResponseCode();
  58.  
  59. if (responseCode == HttpsURLConnection.HTTP_OK) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement