Commit 973d84fa3fdf8a0bb5dda8a0b963a9e160b48331

Authored by JLo'w
1 parent c1f92981

Construction des POST correcte

PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java
@@ -51,12 +51,24 @@ public class NetworkThread extends AsyncTask<Void, Void, JSONObject> { @@ -51,12 +51,24 @@ public class NetworkThread extends AsyncTask<Void, Void, JSONObject> {
51 51
52 httpCo.connect(); 52 httpCo.connect();
53 53
54 - OutputStreamWriter wr = new OutputStreamWriter(httpCo.getOutputStream()); 54 + boolean debut = true;
  55 + StringBuilder buffer = new StringBuilder();
  56 +
55 for (Map.Entry<String, String> entry : mParam.entrySet()) { 57 for (Map.Entry<String, String> entry : mParam.entrySet()) {
56 - String key = entry.getKey();  
57 - String value = entry.getValue();  
58 - wr.write(key + "=" + value); 58 + if(debut){
  59 + debut = false;
  60 + }
  61 + else
  62 + {
  63 + buffer.append("&");
  64 + }
  65 + buffer.append(entry.getKey());
  66 + buffer.append("=");
  67 + buffer.append(entry.getValue());
59 } 68 }
  69 +
  70 + OutputStreamWriter wr = new OutputStreamWriter(httpCo.getOutputStream());
  71 + wr.write(buffer.toString());
60 wr.flush(); 72 wr.flush();
61 73
62 String response = ""; 74 String response = "";
@@ -68,7 +80,7 @@ public class NetworkThread extends AsyncTask&lt;Void, Void, JSONObject&gt; { @@ -68,7 +80,7 @@ public class NetworkThread extends AsyncTask&lt;Void, Void, JSONObject&gt; {
68 response += line; 80 response += line;
69 } 81 }
70 } else { 82 } else {
71 - response = "Erreur"; 83 + response = "{\"status\":" + httpCo.getResponseCode() + "}";
72 } 84 }
73 85
74 json = new JSONObject(response); 86 json = new JSONObject(response);