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

前端 未结 8 1334
孤街浪徒
孤街浪徒 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:44

    The correct(but a bad) way to do it ,as I found out, is to allow all certificates.

    HttpClient client = new HttpClient();
    client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
    
    String url ='xyz@xyz.com';
    
    Map map = { 
         "email" : "email" , 
         "password" : "password"
    };
    
    HttpClientRequest request = await client.postUrl(Uri.parse(url));
    
    request.headers.set('content-type', 'application/json');
    
    request.add(utf8.encode(json.encode(map)));
    
    HttpClientResponse response = await request.close();
    
    String reply = await response.transform(utf8.decoder).join();
    
    print(reply);
    

提交回复
热议问题