Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when using https with flutter http.dart package

Tags:

http

flutter

i am usin http.dart package to make http post for login, everything is work good when my restful api in localhost and with (http protocol), but when upload my backend api to shared host with (https protocol):

I/flutter (12071): HandshakeException: Handshake error in client (OS Error:
I/flutter (12071):      CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:363))

this is my code for http request:

final res = await http
    .post(Uri.encodeFull(url),
     body: {"email": _user.text, "password": _pass.text},
     headers: {'Accept' : 'application/json'});

this is all debug message:

E/flutter (12071): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (12071): HandshakeException: Handshake error in client (OS Error:
E/flutter (12071):      CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:363))
E/flutter (12071): #0      IOClient.send (package:http/src/io_client.dart:33:23)
E/flutter (12071): <asynchronous suspension>
E/flutter (12071): #1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38)
E/flutter (12071): <asynchronous suspension>
E/flutter (12071): #2      BaseClient.post (package:http/src/base_client.dart:54:7)
E/flutter (12071): #3      post.<anonymous closure> (package:http/http.dart:70:16)
E/flutter (12071): #4      _withClient (package:http/http.dart:166:20)
E/flutter (12071): <asynchronous suspension>
E/flutter (12071): #5      post (package:http/http.dart:69:5)
E/flutter (12071): #6      LoginState._login (package:mis/auth/login.dart:41:23)
E/flutter (12071): <asynchronous suspension>
E/flutter (12071): #7      LoginState.build.<anonymous closure> (package:mis/auth/login.dart:216:31)
E/flutter (12071): #8      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter (12071): #9      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
E/flutter (12071): #10     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (12071): #11     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter (12071): #12     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
E/flutter (12071): #13     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (12071): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:184:20)
E/flutter (12071): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter (12071): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter (12071): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (12071): #18     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter (12071): #19     _invoke1 (dart:ui/hooks.dart:168:13)
E/flutter (12071): #20     _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
like image 983
Osama Mohammed Avatar asked Oct 17 '22 06:10

Osama Mohammed


1 Answers

According to https://github.com/flutter/flutter/issues/27883

Just add

<uses-permission android:name="android.permission.INTERNET" />

in your app's android/app/src/main/AndroidManifest.xml

like image 75
Raymond Ativie Avatar answered Dec 23 '22 18:12

Raymond Ativie