SocketIOException: Unexpected handshake error in client SocketIOException: Unexpected handshake error in client dart dart

SocketIOException: Unexpected handshake error in client


Update: See the answer of William Hesse for Dart version >= 1.12.


I have the same error with Dart SDK version 0.2.9.9_r16323. In 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.

Thus, by adding SecureSocket.initialize() before your code, it works as expected.

After r16384 this explicit 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.


The secure networking library has changed since this question was written. There is no SecureSocket.initialize() function anymore, and many other methods and objects have changed names. The working equivalent code for Dart 1.12 and later is:

import "dart:io";main() async {  Uri url = Uri.parse("https://www.google.com");`  var client = new HttpClient();  var request = await client.getUrl(url);  var response = await request.close();  var responseBytes = (await response.toList()).expand((x) => x);  print(new String.fromCharCodes(responseBytes));  client.close();}