【发布时间】:2017-01-09 12:55:25
【问题描述】:
我正在尝试使用 api(用 PHP 编写)并使用它发布参数。 这是我的代码:
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
url, null,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println("prerna succes volley "+response.toString());
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("prerna fail volley "+error.toString());
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> pars = new HashMap<String, String>();
pars.put("Content-Type", "application/x-www-form-urlencoded");
return pars;
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("action", "login");
params.put("username", "abc@xyz.com");
params.put("pass", "a");
return params;
}
};
如果用户名和密码无效,我总是得到在 api 中处理的无效用户名/密码。在这种情况下,api 没有收到参数。 我尝试通过改造来做到这一点,并且它可以正常工作,这意味着 API 编码没有问题。如果凌空抽射,我在这里错过了什么?
【问题讨论】: