【发布时间】:2019-08-30 06:28:11
【问题描述】:
我正在使用http dart 库访问 API,同时我得到 302 状态代码。我知道 302 状态码是用于重定向的,你能说我如何在http post 方法中启用重定向。我使用了以下代码:
Future<LoginModel> login(String username, String password) async {
var client = new http.Client();
final response =
await client.post(LOGIN_URL +"username=Student&password=2018" ,
headers: {'Content-type': 'application/json',
'Accept': 'application/json'});
if (response.statusCode == 200) {
return LoginModel.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to load post');
}
}
【问题讨论】: