这是我的安卓代码
JSONObject params = new JSONObject();
params.put("username","rajesh@gmail.com");
params.put("password","hellothere");
JsonObjectRequest loginRequest = new JsonObjectRequest(
Request.Method.POST,
"http://192.168.2.67/tmp/test.php",
params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
Log.d("","");
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.d("","");
}
});
requestQueue.add(loginRequest);
php 中的服务器代码
<?php
$usr = $_REQUEST['username'];
$pwd = $_REQUEST['password'];
$resp[$usr]=$pwd;
echo json_encode($resp);
?>
我得到的回应是 {"":null}
我尝试使用 apache http cleint,它工作得很好 有什么办法可以用 volley 做到这一点吗?
最佳答案
To send parameters in request body you need to override either getParams() or getBody() method of the request classes
关于android - 如何在 Volley 中发送带有数据的 post 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429426/