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.
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
HttpClientfromdart:iousing the options you are interested in. Pass it toIOClient(httpClient)to wrap it as a aClientfrom 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
Most helpful comment
Like this?