将https与flutter http.dart包一起使用时出错

时间:2019-02-16 23:34:39

标签: http flutter

我是使用http.dart程序包来进行http登录登录的,当我在localhost上使用(http协议)的静态api时,一切正常,但是当使用(https协议)将我的后端api上传到共享主机时,一切正常/ p>

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))

这是我的http请求代码:

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

这是所有调试消息:

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)

2 个答案:

答案 0 :(得分:1)

根据https://github.com/flutter/flutter/issues/27883

只需添加

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

在应用程序的 android / app / src / main / AndroidManifest.xml

答案 1 :(得分:0)

添加<uses-permission android:name="android.permission.INTERNET"/> 在您应用的 android / app / src / main / AndroidManifest.xml 文件中

并确保您的设备可以连接互联网。