Pation
Pation

Reputation: 159

Get data from API Flutter

Can anyone explain me how can I retrieve data from API https://185.86.145.54/cameras/all I tried to parse as http, didn't work. Every time I got this issue HandshakeException (HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: self signed certificate(handshake.cc:354))) I tried use HttpClient and I could get API body, but I don't know how can I show values of API parameters in application.

Upvotes: 0

Views: 287

Answers (3)

Noah
Noah

Reputation: 193

You need to get the data in an asynchronous function with a Future type and then use a FutureBuilder widget to display the data. I've also linked an article about building an RSS Feed in flutter, that helped me to understand how to get data from the web.

https://medium.com/@scottingram.scott/hacker-news-rss-app-in-flutter-976728b09361

Upvotes: 1

Sisir
Sisir

Reputation: 5388

General thumb rule: If the server (API) is based on https (TLS) then the client should connect using https. If the server uses http (non-TLS) then the client should use http to connect to it.

Certificate verification is part of a process named HandShaking which is the first step in a TLS (HTTPS) based communication.

In your case, the API you are trying to hit is an https ( https://185.86.145.54/cameras/all) type but it seems that your using Uri.http() to do the connection which will not provide any client side certification as it is non-TLS (http) resulting in your runtime exception.

Hence to fix your current problem from your flutter app you should use:

Uri uri = Uri.https("185.86.145.54/cameras/all");
http.get(uri); //http is from the import 'package:http/http.dart' as http;

Upvotes: 1

DonnC
DonnC

Reputation: 67

You can use this online tool https://app.quicktype.io/ to generate your Dart Model Classes you will use to get api parameters in your application, simply paste the json response from your api. The approach is to make a model out of your api response

For the Handshake error, see this post stackoverflow

Upvotes: 1

Related Questions