我使用Django,当用户通过API登录时,发送到Android的响应包含一个cookie,其中包含CSRF和Session,我需要接收它的值并在下一个请求的Header中发送它们.我试了很多,但还是没有找到解决办法
private void test() {
RequestQueue requestQueue;
requestQueue = Volley.newRequestQueue(this);
String url_ = "https://xxxx.com/api/BF";
Map<String, String> params = new HashMap<>();
params.put("Email", UEmail);
params.put("Password", UPassword);
JSONObject JOParams = new JSONObject(params);
JsonObjectRequest JORequest = new JsonObjectRequest(Request.Method.POST, url_, JOParams, response -> {
try {
String status_ = response.getString("Status");
if (status_.equals("OK_")) {
Toast.makeText(this, "Login", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Login failed", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(this, "Data error", Toast.LENGTH_SHORT).show();
}
}, error -> {
Toast.makeText(this, "Connection failed", Toast.LENGTH_LONG).show();
});
requestQueue.add(JORequest);
}
}
请完成代码.我判断了所有以前的答案,但没有得到任何结果