我正在尝试使用带有身份验证令牌的oauth 2.0和自定义服务器来创建登录截击发布请求。正文:
{
"customer": {
"email": "[email protected]",
"password":"12345"
}
}
我尝试过此
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
final Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer .....UzI1NiIsInR5cCI6IkpXVCJ9.....");
headers.put("email",username.toString());
headers.put("password",password.toString());
headers.put("customer",headers.toString());
Log.e("Json created", headers.toString());
return headers;
}
如果要作为JSON主体传递数据,请执行此操作。
String body = "{\"customer\":{\"email\":"+ username + ",\"password\":"+ password +"}}";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, response -> {
//response here
}, error -> {
//exceptions here
}) {
@Override
public byte[] getBody() throws AuthFailureError {
return body.getBytes();
}
@Override
public HashMap<String, String> getHeaders() throws AuthFailureError {
final HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer .....UzI1NiIsInR5cCI6IkpXVCJ9.....");
return headers;
}
};