Send json data from client to server using volley library


I want to send a simple message from client to server (the server is not localhost). I use Volley library and the method POST.
When I run the code did not make the connection, LogCat prints 2.onErrorResponse: Error:

Client code:

String url = "";
RequestQueue queue;
JsonObjectRequest request;
Map<String, String> map = new HashMap<String, String>();

protected void onCreate(Bundle savedInstanceState) {


    queue = Volley.newRequestQueue(this);

    map.put("param1", "example");

    request = new JsonObjectRequest(Request.Method.POST, 

            new JSONObject(map), 
            new Response.Listener<JSONObject>() { 
                public void onResponse(JSONObject response) {

                    try {
                        VolleyLog.v("Response:%n %s", response.toString(7));
                    } catch (JSONException e) {
            }, new Response.ErrorListener() { 
                public void onErrorResponse(VolleyError error) {

                    VolleyLog.e("Error: ", error.getMessage());


PHP Server code

$jsondata = $_POST[‘param1’];

$json = json_decode($jsondata,true);

echo $json ;

Can someone help?

Source: json

1 Comment

  1. Edwin

    Here you try to decode non json type into json. The $post[‘param1’] is the string value which you can request form the your app to server just print $post[‘param1’] is the String format not a json

    $jsondata = $_POST['param1'];
    echo $json_encode($_POST)  ;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.