【发布时间】:2019-07-08 14:59:17
【问题描述】:
我正在向 wp-rest-api 发送 POST 请求以获取令牌,以便从 android 应用程序登录用户,无论我在这里传递的用户名和密码是我的请求代码,我都会得到相同的响应
private void login() {
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST,url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//
Toast.makeText(MainActivity.this, "bad", Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","isohunter1@hotmail.com");
params.put("password","qweqweqwe123");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
return params;
}
};
queue.add(sr);
}
【问题讨论】:
标签: android android-volley token wordpress-rest-api