我想用一个简单的令牌执行一个基本的身份验证;如何在颤振中执行此操作?这是最好的方法?
var response = await httpClient.post(url,
body: {'name': 'doodle', 'color': 'blue'});
Run Code Online (Sandbox Code Playgroud)
以这种方式添加身份验证标头是否足够?
var response = await httpClient.post(
url,
header:{
'authorization' : 'bearer $token',
'content-type':'application/json'
},
body :{some body});
Run Code Online (Sandbox Code Playgroud)
我正在使用 JWT 令牌类型
你可以使用这样的东西。
var request = new http.Request('POST', Uri.parse(url));
request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json';
request.headers[HttpHeaders.AUTHORIZATION] = token;
request.body = json.encode(loginRequest.toMap());
await client.send(request).then((response) {
response.stream.bytesToString().then((value) {
print(value.toString());
jsonResponse = value.toString();
completer.complete(jsonResponse);
});
}).catchError((error) {
print(error.toString());
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7045 次 |
最近记录: |