1

Here in the basement, we're writing a messenger app for android. We have basically figured out the logic but for the following: - At the initial launch of the app on the phone, we need to register the user - The server API (being written in PHP) must receive the data, such as phone number and uid, sent by the phone using POST request in json format. As you know, to process the POST data in PHP, you need to know the global variable, as listed here:

$_POST['some_var'];

The questions is, how can I know this global variable to process in my PHP script?

Donik
  • 33
  • 6

1 Answers1

0

Usually you define the POST Key in your android code. For example if you use the AsyncHttpClient (http://loopj.com/android-async-http/) you are doing something like

RequestParams params = new RequestParams();
params.put("key", "value");
params.put("more", "data");

AsyncHttpClient client = new AsyncHttpClient();
client.post("http://www.google.com", params, new AsyncHttpResponseHandler() {

    @Override
    public void onStart() {
        // called before request is started
    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, byte[] response) {
        // called when response HTTP status is "200 OK"
    }    

    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
        // called when response HTTP status is "4XX" (eg. 401, 403, 404)
    }

    @Override
    public void onRetry(int retryNo) {
    // called when request is retried
    }
});

Where the RequestParams define your POST variables which are send to the PHP script. For this example you will get following $_POST values in your PHP script.

$_POST['key'] // "value"
$_POST['more'] // "data"
mapodev
  • 988
  • 8
  • 14