我使用Web服务进行图像处理,它在Postman中运行良好:
现在我想用Dart扑灭http请求:
import 'package:http/http.dart' as http;
static ocr(File image) async {
var url = '${API_URL}ocr';
var bytes = image.readAsBytesSync();
var response = await http.post(
url,
headers:{ "Content-Type":"multipart/form-data" } ,
body: { "lang":"fas" , "image":bytes},
encoding: Encoding.getByName("utf-8")
);
return response.body;
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何上传图像文件,在上面的代码中我得到异常:Bad state: Cannot set the body fields of a Request with content-type "multipart/form-data".
我应该如何编写请求体?