【发布时间】:2021-11-11 01:53:17
【问题描述】:
如何用flutter实现JWT令牌刷新?
我需要使用哪个包?
可以用 HTTP 包实现吗?
我的尝试
getauth(String username, String password) async {
http.post(url, body: {
'username': "atom",
'password': "abi",
'grant_type': "password",
'client_id': "2LJhXdj2Cu0LlVqHk2ilm1WWHtdwK**********",
'client_secret':
"buQIh6tLPC0hG6QZUMm7yP7QuSjBLiffTBx3zY2HYxw95ssXQ4F85ttE5fGHInm1LBkk9GhGiHZCvoR21l4bqIOQTTJBo0nJ5******************"
}).then((response) {
Map<String, dynamic> responseMap = json.decode(response.body);
if (response.statusCode == 200) {
print(response.body);
}
print(response.body);
});
}
【问题讨论】:
-
你需要使用拦截器。拦截器允许我们使用 HttpClient 拦截传入或传出的 HTTP 请求。通过拦截HTTP请求,我们可以修改或改变请求的值。
-
http插件能处理拦截器吗?
-
检查我的答案