【发布时间】:2021-05-20 03:56:27
【问题描述】:
我的应用程序向服务器发出大量 HTTP 请求。在其上安装 SSL 证书后,应用程序崩溃了。
我的服务器运行 Ubuntu,Nginx 托管 PHP 代码(使用证书和工作)并“代理”用 NodeJS 编写的应用服务器代码。在我更改为 HTTPS 之前它一直有效。
我的 POST 请求典型用法:
var jsonRequest = //Some JSON.
Map<String, String> headers = {'Content-type': 'application/json'};
var response = await http.post(urls['auth'], body: jsonRequest,headers: headers);
我得到的错误:
E/flutter (25875): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter (25875): WRONG_VERSION_NUMBER(tls_record.cc:242))
E/flutter (25875): #0 IOClient.send (package:http/src/io_client.dart:33:23)
E/flutter (25875): <asynchronous suspension>
E/flutter (25875): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38)
E/flutter (25875): <asynchronous suspension>
E/flutter (25875): #2 BaseClient.post (package:http/src/base_client.dart:54:7)
E/flutter (25875): #3 post.<anonymous closure> (package:http/http.dart:70:16)
...
【问题讨论】:
-
通常情况下,当 HTTPS 客户端到达 HTTP 端点时会发生这种情况,因此根本无法获得正确的 TLS。确保在您使用的 URL 中有正确的 TLS (HTTPS) 服务器。易于使用 curl、wget、openssl s_client 或任何在线 TLS 网络服务器检查器进行测试。
-
谢谢。我尝试使用 curl 并得到了同样的错误。看起来我直接连接到节点(HTTP)服务器而不是 NGINX,更改了端口并且它消失了。
-
在颤振 2.0 中通过将 Url(...) 而不是 Url.parse(...) 传递给 http.post 方法修复了相同的问题。