我正在从我的Flutter应用发出https发布请求。因为我在服务器中使用了自签名SSL证书,所以当我点击API时,我收到的状态码为405,表明我无法连接,
如果我使用HTTP包,则会出现以下异常情况
HandshakeException: Handshake error in client (OS Error: I/flutter ( 7107): CERTIFICATE_VERIFY_FAILED: self signed certificate(handshake.cc:352))
当我尝试使用deo软件包时,我得到405状态代码,下面是该代码,
Response response;
final Dio dio = Dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
return client;
};
response = await dio.post(loginURL, data: {"username": username, "password": password});
print(response.data.toString());
print(response.statusCode);
我试图通过
来避免SSL握手 client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
仍然无法使用其他解决方案吗?
答案 0 :(得分:0)
正如前面评论中提到的,HTTP 请求通过,因为它返回一个 405 error
。 HTTP 错误 405 常见点通常定义为“方法不允许”,通常由错误的请求方法引起。您可能需要检查服务器是否可以接收您发送的请求。