Flutter HTTP标头 [英] Flutter http headers
问题描述
设置标题映射时,发布请求引发错误。
The post request throwing error while setting the header map.
这是我的代码
Future<GenericResponse> makePostCall(
GenericRequest genericRequest) {String URL = "$BASE_URL/api/";
Map data = {
"name": "name",
"email": "email",
"mobile": "mobile",
"transportationRequired": false,
"userId": 5,
};
Map userHeader = {"Content-type": "application/json", "Accept": "application/json"};
return _netUtil.post(URL, body: data, headers:userHeader).then((dynamic res) {
print(res);
if (res["code"] != 200) throw new Exception(res["message"][0]);
return GenericResponse.fromJson(res);
});
}
`══╡手势引起的异常╞═
抖动:处理手势时抛出了以下断言:
flutter:类型'_InternalLinkedHashMap'不是'Map'类型的子类型此错误消息中的信息可帮助您确定和解决根本原因。
抖动:无论哪种情况,请通过在GitHub上提交错误来报告此断言:
抖动: https://github.com/flutter/flutter/issues/new?template=BUG.md
抖动:
抖动:发生异常时被抛出,这是堆栈:
抖动:#0 NetworkUtil.post1(package:saranam / network / network_util.dart:50:41)
抖动:#1 RestDatasource.bookPandit(package:saranam / network / rest_data_source.dart:204:21)
`══╡ EXCEPTION CAUGHT BY GESTURE ╞═ flutter: The following assertion was thrown while handling a gesture: flutter: type '_InternalLinkedHashMap' is not a subtype of type 'Map' flutter: flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially flutter: more information in this error message to help you determine and fix the underlying cause. flutter: In either case, please report this assertion by filing a bug on GitHub: flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md flutter: flutter: When the exception was thrown, this was the stack: flutter: #0 NetworkUtil.post1 (package:saranam/network/network_util.dart:50:41) flutter: #1 RestDatasource.bookPandit (package:saranam/network/rest_data_source.dart:204:21)
有人遇到这个问题吗?我没有找到上述日志的任何线索。
Anybody facing this issue? I didn't find any clue with the above log.
推荐答案
尝试
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': '<Your token>'
};
这篇关于Flutter HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!