dio代码为:
Future<List> apiRequest(int N ,File file) async {
String url = "http://10.0.2.2:5000/";
// HttpClient httpClient = new HttpClient();
Post _post = Post();
var bytes = await file.readAsBytes();
//TODO : dio post request
var dio = new Dio();
MultipartFile multipartFile = new MultipartFile.fromBytes(bytes);
FormData formData = new FormData();
dio.options.headers = {"content-type" :"multipart/form-dataitem"};
formData.fields.add(MapEntry("index" , N.toString()));
formData.files.add(MapEntry("file",multipartFile));
print(formData);
await dio.post(url, data: formData,options: Options(
method: 'POST',
responseType: ResponseType.json // or ResponseType.JSON
)).then((response){
//response stuffs
});
邮递员的要求: this image consists of my postman's Post request which works fine
我的烧瓶声明使用此表单数据是:
fromJson = request.form['index']
Img = request.files['file']
烧瓶控制台中的错误是:
{exception: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.}