gpt4 book ai didi

javascript - 如何在 flutter 中检索访问 token 值

转载 作者:IT王子 更新时间:2023-10-29 07:12:14 26 4
gpt4 key购买 nike

我有这个代码来获取访问 token :

       Future<Null> getData() async {

var url = "http://192.168.1.23:7070/api/v2/token";
http.post(url, body:{
"grant_type": "string",
"branchcode": "string",
"password": "string",
"username": "string",
"dbname": "string",
"dbuser": "string",
"dbpassword": "string",
"dbtype": "string"
}).then((response){
print("Response Status: ${response.statusCode}");
print("Response Body: ${response.body}");
});
}

运行此代码块后,它会返回如下内容:

Response Body: {"access_token":"AQAAANCMnd8BFdERjHoAwE_Cl-sBAAAAgUTYyajkrEKWAWNrBvgpHQAAAAACAAAAAAAQZgAAAAEAACAAAAB-c92RaHBUfb0aNvnWFqx3JW29bBeQPIouZVDHsTsg8QAAAAAOgAAAAAIAACAAAAC7JdwAlRh8ckP3gAG4vc6H-nULfmjfpBF-gleCcFXeFzABAACJft4ZnsMt1clpRHUTAbiWQIqo5Zmt7_Qc7-pDPwA33O7z3VgFhkx2ITLn5xWGKcVHTkxOxPeRe4qrgEDbsd8V6DHcuwirPkAZye5zECUllxE6IDkNetLkTQsLuK2CpSWxAksFzUS6vhiU7fqkNKsXegtOV--0wFzWsq-ikTjYWnr4LsdAiSUfy_HsTMvLxoIjIqDSxw0QyMM1I2eVIE2wSsZSpoYn3CQIGejQAlG_mUIgzt3PBqEZ6kqIX-Qhx4jpcypUOG5GFNMKLUJa5mti1UiTi8ETpVN_8y_tDhVi-9AS2MJpJN7-Gao_fIB5s0yaH_m9fHkwFgXF1N-Y5GevDypdNryQWbHXQkf88DKZnljMSGzJkJhpzls3PTN8iwss32CXbeO1zaWm-iJAgMK_QAAAACVQGecH57e1QB-FRu2iCt-d6x37x6MJ-_H_H8uYOKbZYBX0lA1b8WxteCLWPM5mAJR1p3tHE_VBqQqvS4pKGHM","token_type":"bearer","expires_in":1199,"refresh_token":"f8de12c7a90b401b9400b93b4cf2c128"

我的问题是,如何在此代码块中检索“access_token”的值?

最佳答案

您可以通过以下方式访问响应

1.如果它来自响应 header ,您可以使用

response.headers['access-token']

2.如果它来自响应主体,您可以使用

访问它
  print('access token is -> ${json.decode(response.body)['access_token']}');

3.如果你正在获取对象,你可以解析它并使用它转换为所需的类型

final Map<String, dynamic> data = json.decode(response.body)['user'].cast<String, dynamic>();

关于javascript - 如何在 flutter 中检索访问 token 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55240238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com