Simple GET request to a Rest API in flutter

Asked

Viewed 2,121 times

0

I’m trying to get a json by making a request to an API, but it’s making a mistake when making the request.

Follows the code:

Future<Map> timeStamp() async {
  const request =
      "https://armariosinteligentes.com/api/v3/timestamp";
  http.Response response = await http.get(request);
  print(json.decode(response.body));
}

This is the json of the request

{"timestamp":1566397501}

Mistake you’re making

E/flutter ( 7041): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Handshakeexception: Handshake error in client (OS Error: E/flutter ( 7041): BLOCK_TYPE_IS_NOT_01(padding.c:108) E/flutter ( 7041): PADING_CHECK_FAILED(rsa_impl.c:641) E/flutter ( 7041): public key routines(a_verify.c:105) E/flutter ( 7041): CERTIFICATE_VERIFY_FAILED: Certificate Signature Failure(Handshake.cc:352)) E/flutter ( 7041): #0 Ioclient.send (package:http/src/io_client.Dart:33:23) E/flutter ( 7041): E/flutter ( 7041): #1 Baseclient. _sendUnstreamed (package:http/src/base_client.Dart:169:38) E/flutter ( 7041): E/flutter ( 7041): #2 Baseclient.get (package:http/src/base_client.Dart:32:7) E/flutter ( 7041): #3 get. (package:http/http.Dart:46:36) E/flutter ( 7041): #4 _withClient (package:http/http.Dart:166:20) E/flutter ( 7041): E/flutter ( 7041): #5 get (package:http/http.Dart:46:5) E/flutter ( 7041): #6 timestamp (package:armarios_smart/screens/locker_screen.Dart:196:34) E/flutter ( 7041): E/flutter ( 7041): #7 Lockerscreenstate.build. (package:armarios_intelligent/screens/locker_screen.Dart:114:15) E/flutter ( 7041): #8 _Inkresponsestate. _handleTap (package:flutter/src/material/ink_well.Dart:635:14) E/flutter ( 7041): #9 _Inkresponsestate.build. (package:flutter/src/material/ink_well.Dart:711:32) E/flutter ( 7041): #10 Gesturerecognizer.invokeCallback (package:flutter/src/Gestures/recognizer.Dart:182:24) E/flutter ( 7041): #11 Tapgesturerecognizer. _checkup (package:flutter/src/Gestures/tap.Dart:365:11) E/flutter ( 7041): #12 Tapgesturerecognizer.acceptGesture (package:flutter/src/Gestures/tap.Dart:312:7) E/flutter ( 7041): #13 Gesturearenamanager.Sweep (package:flutter/src/Gestures/arena.Dart:156:27) E/flutter ( 7041): #14 _Widgetsflutterbinding&bindingbase&Gesturebinding.handleEvent (package:flutter/src/Gestures/Binding.Dart:222:20) E/flutter ( 7041): #15 _Widgetsflutterbinding&bindingbase&Gesturebinding.dispatchEvent (package:flutter/src/Gestures/Binding.Dart:198:22) E/flutter ( 7041): #16 _Widgetsflutterbinding&bindingbase&Gesturebinding. _handlePointerEvent (package:flutter/src/Gestures/Binding.Dart:156:7) E/flutter ( 7041): #17 _Widgetsflutterbinding&bindingbase&Gesturebinding. _flushPointerEventQueue (package:flutter/src/Gestures/Binding.Dart:102:7) E/flutter ( 7041): #18 _Widgetsflutterbinding&bindingbase&Gesturebinding. _handlePointerDataPacket (package:flutter/src/Gestures/Binding.Dart:86:7) E/flutter ( 7041): #19 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter ( 7041): #20 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter ( 7041): #21 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter ( 7041): #22 _invoke1 (dart:ui/hooks.dart:250:10) E/flutter ( 7041): #23
_dispatchPointerDataPacket (Dart:ui/Hooks.Dart:159:5) E/flutter ( 7041):

  • which error is returning?

  • [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Handshakeexception: Handshake error in client (OS Error:

1 answer

1


 timeStamp() async {
  final response =
  await http.get('http://armariosinteligentes.com/api/v3/timestamp');

  if (response.statusCode == 200) {
    // If server returns an OK response, parse the JSON.
    var jsonResponse = json.decode(response.body);
    tempoStamp tempo = new tempoStamp.fromJson(jsonResponse);
    var time = ('${tempo.timestamp}');
    return time;
  } else {
    // If that response was not OK, throw an error.
    throw Exception('Failed to load post');
  }
}

Result: 1566411603

Browser other questions tagged

You are not signed in. Login or sign up in order to post.