【发布时间】:2018-10-22 06:43:18
【问题描述】:
我是新来的颤振。基本上我正在为我的 Web 应用程序使用代码 Igniter 框架。我为我的网络应用程序创建了 REST API,在用户使用 API 登录后,所有方法都会检查 session_id 如果它存在则继续,如果不存在则给出
{ ['status'] = false, ['message'] = 'unauthorized access' }
我正在使用颤振创建应用程序,当我使用颤动的 http 方法时,它会更改每个请求的会话。我的意思是,它不维护会话。我认为它每次都会破坏并创造新的联系。这是我用于 api 调用获取和发布请求的 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;
}
我想发出 API 请求,然后存储 session_id, 是否可以在服务器上维护会话,以便我可以在自己的网络应用程序上管理身份验证。
【问题讨论】:
-
嗨,正如 Richard 所说,Http 是无状态的,您可以附加标头作为 http.post 函数的参数。此外,对于移动应用程序,API 通常与授权令牌、身份验证标头等一起使用:flutter.io/cookbook/networking/authenticated-requests 在这里解释:scotch.io/tutorials/… 我认为这对于代码点火器有类似的作用(我从未使用过代码点火器)github.com/benedmunds/CodeIgniter-Ion-Auth
标签: flutter