Http: CERTIFICATE_VERIFY_FAILED

Created on 12 Apr 2019  路  8Comments  路  Source: dart-lang/http

Is there any way to use badCertificateCallback with this package? I am using an api for get/post requests and it throws error "CERTIFICATE_VERIFY_FAILED" when I use http package post or get method, but when HttpClient is used with badCertificateCallback method set to true api responds properly. How can I use http package for the same request?

The way that is reminded in #14 is not available in the last versions of related package.

Most helpful comment

Like this?

import 'package:http/io_client.dart';
import 'dart:io';

    final ioc = new HttpClient();
    ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
    final http = new IOClient(ioc);

All 8 comments

Construct an HttpClient from dart:io using the options you are interested in. Pass it to IOClient(httpClient) to wrap it as a a Client from this package.

Like this?

import 'package:http/io_client.dart';
import 'dart:io';

    final ioc = new HttpClient();
    ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
    final http = new IOClient(ioc);

@duzenko - looks about right.

Construct an HttpClient from dart:io using the options you are interested in. Pass it to IOClient(httpClient) to wrap it as a a Client from this package.

Like this?

import 'package:http/io_client.dart';
import 'dart:io';

    final ioc = new HttpClient();
    ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
    final http = new IOClient(ioc);

I tried this and am still getting CERTIFICATE_VERIFY_FAILED. Any suggestions?

I tried this and am still getting CERTIFICATE_VERIFY_FAILED. Any suggestions?

You might ask for help on stack overflow, or if you think there is a bug in the dart:io HttpClient class you can file an issue on the SDK repo.

@alexfanchina
Please attach a _complete_ repro case

Could you share some example code for how to tell a request object (like MultiPartRequest) to use the constructed IOClient?

EDIT

It's actually pretty obvious - for everyone who comes looking here:

Instead of sending from your Request object like req.send(...);

Send the Request object through your constructed IOClient like ioClient.send(req)

Like this?

import 'package:http/io_client.dart';
import 'dart:io';

    final ioc = new HttpClient();
    ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
    final http = new IOClient(ioc);

final http = new IOClient(ioc);// userful line

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ottomated picture ottomated  路  7Comments

Jonas-Sander picture Jonas-Sander  路  6Comments

Buckstabue picture Buckstabue  路  7Comments

jet10000 picture jet10000  路  5Comments

demos77 picture demos77  路  3Comments