0

i was building a flutter application and i need to get JSON data from a https server.

but i getting error like this

Error: HandshakeException: handshake error in client(OS ERROR: CERTIFICATE_VERIFIY_FAILED: self signed certificate

My ApiServices Code

class ApiAjuService{
  Client client = Client();
  final baseURL = "https://posdemo.sisapp.com:8443/kbs/rest/mock/api/ajus";

  Future<List<Aju>> getAju() async{
    final response = await client.get("$baseURL");
    if(response.statusCode == 200){
      return ajuFromJson(response.body);
    }else{
      return null;
    }

  }

My Model

  List<Aju> ajuFromJson(String jsonData) {
    final data = json.decode(jsonData);
    return List<Aju>.from(data.map((item) => Aju.fromJson(item)));
}

i except the api will show in my listView , but i still get error handshake

Muhammad Faisal
  • 137
  • 2
  • 2
  • 12
  • 1
    Have you looked at [this](https://flutter.dev/docs/cookbook/networking/fetch-data)? – tomerpacific Aug 05 '19 at 10:09
  • yes , look edited question – Muhammad Faisal Aug 05 '19 at 10:13
  • Why are you doing this: `response.statusCode == 401`? – Birju Vachhani Aug 05 '19 at 10:15
  • sorry , before im try get json with```statusCode == 200```, i'll try to get json with ```statusCode == 401```, but im still getting the same error . im just forgot to edit the ```statusCode``` :D – Muhammad Faisal Aug 05 '19 at 10:25
  • The error looks like the SSL certificate is not properly installed. If there is an error in your call to the server, or a bug/error in your code that handles the call you would get either a 500 internal error, a 401 authentication fail or a 404 not found error. Or course, when succesful you'd be getting a 200 or 201 status. You can try these calls with e.g. [Postman](https://www.getpostman.com/)or [InSomnia](https://insomnia.rest/) to see if the http call works as you want it to work. – R. Flierman Aug 05 '19 at 10:45
  • Possible duplicate of [How to do SSL pinning via self generated signed certificates in flutter?](https://stackoverflow.com/questions/51323603/how-to-do-ssl-pinning-via-self-generated-signed-certificates-in-flutter) – Richard Heap Aug 05 '19 at 10:54
  • It's not an exact duplicate, but the answer will work - just return `true` from the closure to accept any and all server certificates. Obviously, don't do this in production :-) – Richard Heap Aug 05 '19 at 10:55
  • still getting the same error , i have a question about @RichardHeap Code, where i should set baseURL? – Muhammad Faisal Aug 06 '19 at 02:42
  • Update the question to show your new code with the bad certificate callback. – Richard Heap Aug 06 '19 at 02:45
  • Good News Problem Has Been Solved Using ```IOClient``` – Muhammad Faisal Aug 06 '19 at 07:34

0 Answers0