https - SocketIOException : Unexpected handshake error in client

标签 https dart

以下异常:

SocketIOException: Unexpected handshake error in client (OS Error: errno = -12268)
#0      _SecureFilterImpl.handshake (dart:io-patch:849:8)
#1      _SecureSocket._secureHandshake (dart:io:7382:28)
#2      _SecureSocket._secureConnectHandler._secureConnectHandler (dart:io:7294:21)
#3      _Socket._updateOutHandler.firstWriteHandler (dart:io-patch:773:64)
#4      _SocketBase._multiplex (dart:io-patch:408:26)
#5      _SocketBase._sendToEventHandler.<anonymous closure> (dart:io-patch:509:20)
#6      _ReceivePortImpl._handleMessage (dart:isolate-patch:37:92)

以下代码的结果:

String url = "https://www.google.com";
HttpClient client = new HttpClient();
HttpClientConnection conn = client.getUrl(new Uri(url));
conn.onResponse = (HttpClientResponse resp) {
  print ('content length ${resp.contentLength}');
  print ('status code ${resp.statusCode}');
  InputStream input = resp.inputStream;
  input.onData = () {
    print(codepointsToString(input.read()));
  };
  input.onClosed = () {
    print('closed!');
    client.shutdown();
  };
};

请注意,如果我将 url 替换为“http”而不是“https”,它会按预期工作。

Bug report is here.

最佳答案

更新 : 见answer of William Hesse对于 Dart 版本 >= 1.12。

我对 Dart SDK version 0.2.9.9_r16323 也有同样的错误.在 the issue 7541 :

The SecureSocket library needs to be initialized explicitly before using secure networking. We are working on making it initialize automatically the first time you use it, but that is not committed yet. To use just the default root certificates (well known certificate authorities), call SecureSocket.initialize() in your main() routine, before you do any networking.



因此,通过添加 SecureSocket.initialize()在您的代码之前,它按预期工作。

r16384这个明确的initialization is optional .

SecureSocket.initialize() is now optional. If you don't call it, it is the same as if you had called it with no parameters. If you call it explicitly, you must do so once, and before creating any secure connections. You need to call it explicitly if you are making server sockets, since they need a certificate database and a password for the key database.

关于https - SocketIOException : Unexpected handshake error in client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13964492/

相关文章:

flutter - 在 RxDart 中用什么代替 "combineLatest2"?

flutter - Flutter-如何控制圆形进度指示器的边框宽度?

android - Flutter:我们检测到您的应用在您的 1 个或多个 app bundle 或 APK 的 list 文件中包含 requestLegacyExternalStorage 标志

generics - 如何在Dart中制作更通用的isEmpty()函数?

.htaccess - 在整个站点范围内删除 www,在某些目录上强制使用 https,在其余目录上强制使用 http?

testing - 认证测试服务器

php - PayPal IPN 监听器 - SSL 证书握手失败

git - 无法使用 http/https 将 Git 推送到远程存储库

java - Spring HTTPS 正在切换到 HTTP : I want to use either HTTPS or HTTP for the site depending on the user

dart - Dart 可以用作通用语言吗?