我正在开发 Flutter 一个应用程序,它将使用基于 Express 的 REST api。在实现基于 Cookie 的会话时,我想通过基本身份验证请求从应用程序检索 cookie,但不知何故我无法检索 cookie 作为响应。当我从 Postman 发出相同的请求时,没有问题,cookie 会自动设置。
我使用 HTTP 包来发出请求,代码非常简单,如下所示。
void login(String username, String password) async {
var url = 'http://$username:$password@111.222.333.444:3333/auth';
var response = await http.get(url);
print('Response header: ${response.headers}');
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}
Run Code Online (Sandbox Code Playgroud)
响应头或正文中没有 cookie。
我是新来的。基本上,我在Web应用程序中使用代码Igniter框架。我为我的Web应用程序创建了REST API,在用户使用API登录后,所有方法都会检查session_id是否存在,然后继续进行,如果不存在,则给出
{ ['status'] = false, ['message'] = 'unauthorized access' }
Run Code Online (Sandbox Code Playgroud)
我正在使用flutter创建应用程序,当我使用flutter的http方法时,它将更改每个请求的会话。我的意思是,它不维护会话。我认为它每次都会破坏并创建新的连接。这是我用于API调用get和post请求的thr类方法。
class ApiCall {
static Map data;
static List keys;
static Future<Map> getData(url) async {
http.Response response = await http.get(url);
Map body = JSON.decode(response.body);
data = body;
return body;
}
static Future postData(url, data) async {
Map result;
http.Response response = await http.post(url, body: data).then((response) {
result = JSON.decode(response.body);
}).catchError((error) => print(error.toString()));
data = result;
keys = result.keys.toList();
return result;
}
Run Code Online (Sandbox Code Playgroud)
我想发出API请求,然后存储session_id,是否可以在服务器上维护会话,以便我可以自行管理Web应用程序上的身份验证?