Bypass Certificate Error Using Http

前端 未结 2 889
谎友^
谎友^ 2021-01-13 04:44

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

2条回答
  •  野的像风
    2021-01-13 05:30

    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.

提交回复
热议问题