比如,如果参数map中value是一个数组,如下代码中的innerParticipateGroups和innerParticipators的value值不能转成toString,否则就会报400
Map params = {
"chamberId":resultId,
"description":remark,
"finishAt":1564979400000,
"innerParticipateGroups":[],
"innerParticipators":[],
"name":meetingName,
"reportId":"",
"scheduleId":"",
"startAt":1564975800000
};
看下Dio(v2.1.0)的GET请求源码:
Future> get(
String path, {
Map queryParameters,
Options options,
CancelToken cancelToken,
ProgressCallback onReceiveProgress,
}) {
return request(
path,
queryParameters: queryParameters,
options: _checkOptions("GET", options),
onReceiveProgress: onReceiveProgress,
cancelToken: cancelToken,
);
}
GET请求的源码中参数接受要求传入的是queryParameters, 所以调用时用queryParameters
response = await dio.get(url, queryParameters: params);
POST源码:
/// Handy method to make http POST request, which is a alias of [Dio.request].
Future> post(
String path, {
data,
Map queryParameters,
Options options,
CancelToken cancelToken,
ProgressCallback onSendProgress,
ProgressCallback onReceiveProgress,
}) {
return request(
path,
data: data,
options: _checkOptions("POST", options),
queryParameters: queryParameters,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
}
POST源码中参数接受有data和queryParameters,调用时key用data,用queryParameters会报400,queryParameters这个key不知道具体怎么用,官方也没具体说明,官方文档中post请求都是用data传参,有懂的大神麻烦给补充一下。
response = await dio.post(url, data : params);
HttpGo() {
dio = Dio(BaseOptions(
baseUrl: 'https://www.***.com/',
headers: getHeaders(),
connectTimeout: 5000,
receiveTimeout: 3000,
));
}
getHeaders () {
return {
'Accept':'application/json, text/plain, */*',
'Content-Type':'application/json',
'Authorization':"**",
'User-Aagent':"4.1.0;android;6.0.1;default;A001",
"HZUID":"2",
};
}
把请求参数数据格式FormData换成Map
如果你觉得对你有用,就点个赞支持一下吧~ 谢谢啦~