[Solved] How to get a reply from PHP for a POST request


Try using this code instead of the way you are going :

public String performPostCall(String requestURL, HashMap<String, String> postDataParams) {
    URL url;
    String response = "";
    try {
        url = new URL(requestURL);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(15000);
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);


        OutputStream os = conn.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
        writer.write(getPostDataString(postDataParams));

        writer.flush();
        writer.close();
        os.close();
        int responseCode = conn.getResponseCode();

        if (responseCode == HttpsURLConnection.HTTP_OK) {
            String line;
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = br.readLine()) != null) {
                response += line;
            }
        } else {
            response = "";

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return response;
}

And then you can get the result by writing the code :

 HashMap<String, String> params = new HashMap<String, String>();
    postDataparams.put("key", value);
 String response = performPostCall("url", postDataParams);

This way you can get the response from your server. On the server side , you just type echo whatever you need to send to the device. Nothing else needs to be done. This Async thread will wait until it gets a response from the server.

Hope this helps.

3

solved How to get a reply from PHP for a POST request