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
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.