0

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

Community
  • 1
  • 1
dashakhe.goli
  • 59
  • 2
  • 7
  • could you elaborate some more? what is the response that you do receive? this could be solved in more than one way depending on the response.. – TommySM Jun 27 '15 at 12:04

1 Answers1

0

I did a gist on this a while back I hope it can help. You won't me uploading images, however you will be sending an example of which you can see on this line:

entityBuilder.addTextBody("someparameter", params.toString());

In the gist I use apache httpclient 4 with Volley. Link to the gist here.

Ali
  • 12,354
  • 9
  • 54
  • 83
  • tnx, but i want send data with POST of GET methods in Volley Library. can you help me? – dashakhe.goli Jun 25 '15 at 10:12
  • That code does use POST. With GET you can just append everything in the URL as long as its not very long and is text. – Ali Jun 26 '15 at 11:34