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 51  
52 52 httpCo.connect();
53 53  
54   - OutputStreamWriter wr = new OutputStreamWriter(httpCo.getOutputStream());
  54 + boolean debut = true;
  55 + StringBuilder buffer = new StringBuilder();
  56 +
55 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 72 wr.flush();
61 73  
62 74 String response = "";
... ... @@ -68,7 +80,7 @@ public class NetworkThread extends AsyncTask&lt;Void, Void, JSONObject&gt; {
68 80 response += line;
69 81 }
70 82 } else {
71   - response = "Erreur";
  83 + response = "{\"status\":" + httpCo.getResponseCode() + "}";
72 84 }
73 85  
74 86 json = new JSONObject(response);
... ...