From 973d84fa3fdf8a0bb5dda8a0b963a9e160b48331 Mon Sep 17 00:00:00 2001 From: JLo'w Date: Sun, 1 May 2016 20:37:42 +0200 Subject: [PATCH] Construction des POST correcte --- PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java b/PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java index c224939..3f68515 100644 --- a/PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java +++ b/PremiereActivite/app/src/main/java/com/example/app_10p5/NetworkThread.java @@ -51,12 +51,24 @@ public class NetworkThread extends AsyncTask { httpCo.connect(); - OutputStreamWriter wr = new OutputStreamWriter(httpCo.getOutputStream()); + boolean debut = true; + StringBuilder buffer = new StringBuilder(); + for (Map.Entry entry : mParam.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - wr.write(key + "=" + value); + if(debut){ + debut = false; + } + else + { + buffer.append("&"); + } + buffer.append(entry.getKey()); + buffer.append("="); + buffer.append(entry.getValue()); } + + OutputStreamWriter wr = new OutputStreamWriter(httpCo.getOutputStream()); + wr.write(buffer.toString()); wr.flush(); String response = ""; @@ -68,7 +80,7 @@ public class NetworkThread extends AsyncTask { response += line; } } else { - response = "Erreur"; + response = "{\"status\":" + httpCo.getResponseCode() + "}"; } json = new JSONObject(response); -- libgit2 0.21.2