【发布时间】:2021-04-02 02:31:29
【问题描述】:
我正在使用颤振应用程序,我想知道我们如何在 POST 请求中传递授权标头。这是我尝试过的代码。我需要帮助才能知道如何以正确的方式做到这一点。
Future<String> addCartItemToDb({String userId}) async {
try {
final res = await http.post(
_baseURL,
headers: {
"Content-Type": "application/json",
"accept": "*/*",
"Authorization": "token"
},
body: jsonEncode({"userId": userID})
);
return _response(res);
}on SocketException {
throw CustomException("No internet Connection");
}on FormatException {
throw CustomException("Bad Response format !");
}
}
此外,我想知道我们如何解码 token 我在标头中传递的 userid 给那个已经登录的用户。
【问题讨论】:
标签: api flutter authentication dart post