am trying to use volley in my project to handle all my Http request since its the most efficient one as far as I know. So I started to learn volley by following AndroidHive Tutorial
My first GET Request was successful. Then I moved on to post request and I failed. I saw on SO as well many people had problems combining post request of volley with php. I believe we cannot access it using the normal way that is $_POST[""] as volley sends a json object to the url which we specify.
There where lots of solution which I tried but dint succeed. Iguess there should be a simple and standard way of using volley with php
So I would like to know what do I need to do in order to receive the json object sent by volley in my php code.
And also how do I check if volley is really sending a json object.
Hoping to find some help.
My volley code to send simple post request:
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", "Droider");
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
My PHP code to receive json object: (I am pretty sure this is the wrong way, I am not that good in php)
<?php
$jsonReceiveData = json_encode($_POST);
echo $jsonReceivedData;
?>
0 comments:
Post a Comment