【发布时间】:2019-11-14 06:07:22
【问题描述】:
我正在发送我的登录表单的发布请求;使用 dart 的 HTTP 库。
在它的回复中,我不知道如何访问标题内容;因为那是令牌所在的位置,我需要在整个会话期间进行进一步操作。
服务器以 JSON 格式发送内容。 (我是新手,请原谅我的无知)
我的主要目的是从我从 POST 请求得到的响应中读取标头内容。
下面是代码sn-p。
var jsonresponse = Map();
Future login() async{
try{
response = await http.post(
baseLog,
body: {
"username": username.text,
"password": password.text
},
);
//json decode
this.jsonresponse = json.decode(this.response);
var token = this.response.headers.get('token'); //an attempt to access the header
//print('token ' + token);
}
catch(ex){
print('Error occured' + ex);
}
}
【问题讨论】: