I'm trying to create a proxy server that access third-party API, but their development end point have certificate error. Is there anyway to bypass ssl error when using http.dart?
import 'package:http/http.dart' as http;
Uri url = Uri.parse("https://url-with-ssl-error.com/endpoint");
http.get(url).then((response) => print(response.body));
and here's the error returned:
Uncaught Error: SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172)
Unhandled exception:
SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172)
#0 _FutureImpl._scheduleUnhandledError.<anonymous closure> (dart:async/future_impl.dart:207:9)
#1 Timer.run.<anonymous closure> (dart:async/timer.dart:17:21)
#2 Timer.run.<anonymous closure> (dart:async/timer.dart:25:13)
#3 Timer.Timer.<anonymous closure> (dart:async-patch:15:15)
#4 _Timer._createTimerHandler._handleTimeout (dart:io:6990:28)
#5 _Timer._createTimerHandler._handleTimeout (dart:io:6998:7)
#6 _Timer._createTimerHandler.<anonymous closure> (dart:io:7006:23)
#7 _ReceivePortImpl._handleMessage (dart:isolate-patch:81:92)
Though this question may be out of date, I should still post a short answer for this, in case of someone in the same trouble. This snippet's from my project:
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
...
HttpClient client = new HttpClient()..badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
var ioClient = new IOClient(client);
http.Response resp = await ioClient.post(uri, body: utf8.encode(json.encode(body)), headers: headers);
...
The issue was mentioned here and also the fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With