以前我创建了一个 REST API,它从颤振移动应用程序获取一个 ZIP 文件和两个其他参数作为输入
var uri = Uri.parse("http://XX.XXX.XX.XX/gatewayapp/userinfo/sendFileToServer/");
var request = http.MultipartRequest('POST', uri);
Map<String, String> headers = {
"Accept": "application/json"
};
//add headers
request.headers.addAll(headers);
request.fields["customerNumber"] = customerNumber;
request.fields['zippassword'] = password;
var file= await http.MultipartFile.fromPath(
'userDetailsFile',
filePath
);
request.files.add(file);
await request.send().then((streamedResponse) async {
....Implemented the business logic on the response which I was getting
}
它按预期工作。
我们使用 AWS 服务器上的 Nginx 将 API 从HTTP 移动到 HTTPS,并使用 HTTPClient 和 HttpClientRequest 更改了移动应用程序的所有 GET 和 POST 调用,它按预期工作。
但是,我们无法在 API 上使用 HTTPClient 和 HttpClientRequest 进行多部分请求。我尝试使用 httpclient 方法,但没有运气。我还尝试了以下链接中给出的内容:
在 Dart lang github 上使用 HTTPClient
var uri = Uri.parse("https://XX.XXX.XX.XX/gatewayapp/userinfo/sendFileToServer/");
HttpClient client = await CommonController.createHttpClient();
HttpClientRequest request = await client.post( uri.toString() , 443, filePath);
谁能帮助我朝着正确的方向前进?任何帮助,将不胜感激!谢谢