如何解决Flutter Dio在Laravel服务器上发送空白请求
Flutter代码:
普通数据JSON对象
var data = {
'society_id': widget.societyId,'name': _currentCategory,'details': txtDescription.text,'type': "Society Residential Complaint"
};
Dio请求的FormData
FormData formData = FormData.fromMap({
'society_id': widget.societyId,'type': "Society Residential Complaint"
});
if (selectedFile != null) {
String path = selectedFile.path;
String imagename = selectedFile.path.split('/').last;
print("Photo Selected");
formData.files.add(
MapEntry(
"photos[]",await MultipartFile.fromFile(
path,filename: imagename.toString(),),);
}
将发出Dio Post请求的功能
Future raiseComplaint(FormData formData,data) async {
await _getToken();
String requestUrl = serverURL + '/complaint/add';
print("Sending Req: $requestUrl");
print("--- complaint details: $formData");
print("--- complaint details: $data");
try {
dio.options.headers['Content-Type'] = 'application/json';
dio.options.headers["Authorization"] = "Bearer $_accessToken";
Response serverResponse = await dio.post(requestUrl,data: formData);
var response = _returnResponse(serverResponse);
print("Recieving Res: $requestUrl");
print(response);
return response;
} catch (e) {
throw e;
}
}
通话请求
var response = await raiseComplaint(formData,data);
问题:
如果我发送普通的json对象,则来自raiseComplaint()函数,表示正在接收所有参数。我也需要附件文件,因此使用Dio FormData对象。我无法在服务器上接收到的fields
映射中的所有参数和files
映射中的附件的FormData对象。
在(Laravel)服务器上,由于laravel验证失败,我没有从请求中获取任何参数或文件。我搜索了Dio package documentation,但没有找到太多帮助。我们需要按照Dio的要求提出建议,所以如果以前有人遇到此错误,请寻求帮助。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。