I've developed a Application that i'm going to send data from the phone to the server by Json
, to do this i use Volley
Library in Android.
but i can not send data to the server!
my simple php code :
$name = $_GET["name"];
$j = array('name' =>$name);
echo json_encode($j);
my java code :
private void makeJsonObjectRequest() {
mRequestQueue = Volley.newRequestQueue(this);
String url = "http://my-site-name/sampleGET.php";
StringRequest jsonObjReq = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("result:", response);
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("err", "Error: " + error.getMessage());
makeJsonObjectRequest();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("name", "json");
return params;
}
};
mRequestQueue.add(jsonObjReq);
}
It also got help from the link below : Click to see link
But still could not use it and send data from mobile to server!!!
How can I do this?
Please give me correct and how to use it