网络请求如果需要body参数要怎么传呀?
来源:4-1 本章目标

云天化信息科技
2021-07-06
网络请求如果需要body参数要怎么传呀?if (request.httpMethod() == HttpMethod.GET) {
response = await dio.get(request.url(), options: options);
} else if (request.httpMethod() == HttpMethod.POST) {
response = await dio.post(request.url(),
data: request.body,
queryParameters: request.params,
options: options);
} else if (request.httpMethod() == HttpMethod.DELETE) {
response = await dio.delete(request.url(),
data: request.params, options: options);
}
我这样写好像有问题,params被添加了两次id和look
http://xx.xx.xx.xx/form/automForm/getFormInfo/form_53aa4461a279a2d8?look=false&id=a925d4530f1246fb8d11bb73b79f22bf&look=false&id=a925d4530f1246fb8d11bb73b79f22bf
我的body在baseRequest
dynamic body;
///添加body
BaseRequest addBody(String bodyStr) {
body = bodyStr;
return this;
}
上面那个请求我的body并没有传值,是否有更合适的办法呀?
1回答
-
CrazyCodeBoy
2021-07-07
body在传递给data就可以了,另外.url()已经添加过查询参数了不需要在添加queryParameters了。
00
相似问题