how to solve flutter CERTIFICATE_VERIFY_FAILED error while performing a POST request?

前端 未结 8 1348
孤街浪徒
孤街浪徒 2020-11-27 19:54

I am sending a post request in Dart. It is giving a response when I test it on API testing tools such as Postman. But when I run the app. It gives me the following error:- <

8条回答
  •  隐瞒了意图╮
    2020-11-27 20:47

    import 'package:http/io_client.dart';
    import 'dart:io';
    import 'package:http/http.dart';
    import 'dart:async';
    import 'dart:convert';
    
        Future getAccessToken(String url) async {
          try {
            final ioc = new HttpClient();
            ioc.badCertificateCallback =
                (X509Certificate cert, String host, int port) => true;
            final http = new IOClient(ioc);
            http.post('url', body: {"email": "xyz@xyz.com", "password": "1234"}).then(
                (response) {
              print("Reponse status : ${response.statusCode}");
              print("Response body : ${response.body}");
              var myresponse = jsonDecode(response.body);
              String token = myresponse["token"];
            });
          } catch (e) {
            print(e.toString());
          }
        }
    

提交回复
热议问题