我在 Dart 中发送了一个 post 请求,当我在 API 测试工具(如 Postman)上测试它时,它给出了响应。但是当我运行应用程序时。它给了我以下错误:-
这是我的函数代码 -
var request =
http.MultipartRequest('POST', Uri.parse('https://myurl/files/'));
request.files.add(await http.MultipartFile.fromPath('file', pathfile));
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
} else {
print(response.reasonPhrase);
}
错误
E/flutter ( 6264): HandshakeException: Handshake error in client (OS Error: E/flutter ( 6264): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:363))
答案 0 :(得分:1)
**main.dart**
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true; }}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = new MyHttpOverrides();
runApp(Myapp());}