【发布时间】:2018-10-01 03:15:55
【问题描述】:
我在使用 http dart 库的颤振应用程序上使用 Method.Post 时遇到问题。似乎当我尝试从我的 WebAPI 发布数据时,它给了我一个StatusCode 415。请参阅下面的代码:
代码登录:
Future<User> login(User user) async {
print(URLRequest.URL_LOGIN);
return await _netUtil.post(Uri.encodeFull(URLRequest.URL_LOGIN), body: {
'username': user.username,
'password': user.password
}, headers: {
"Accept": "application/json",
}).then((dynamic res) {
print(res.toString());
});
}
代码 NetworkUtils:
Future<dynamic> post(String url, {Map headers, body, encoding}) async {
return await http
.post(url, body: body, headers: headers, encoding: encoding)
.then((http.Response response) {
final String res = response.body;
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode > 400 || json == null) {
throw new Exception('Error while fetching data.');
}
return _decoder.convert(res);
});
}
有人知道我的代码发生了什么吗?
【问题讨论】: