Flutter中的HTTP响应 [英] HTTP-Response in Flutter

查看:292
本文介绍了Flutter中的HTTP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对扑打有​​疑问。我想从网站获取HTTP响应,但是它不起作用。该示例适用于其他网站,但不适用于必需的网站。
代码:

I have a problem with flutter. I want to get the HTTP-Response from a website, but it doesn´t work. The example works with other websites, but not with the required website. Code:

Future initiate() async {
var client = Client();
Response response = await client.get(
‘https://www.phwt.de’
);

我收到此错误:

E/flutter (18017): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter (18017): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:352))


推荐答案

之所以会发生此问题,是因为flutter不知道谁为 www.phwt.de 签名或颁发了证书。该证书似乎已经由SwissSign AG签署,要使其正常工作,您可以使用以下选项:

The problem happens because flutter does not know who signed or issued the certificate for www.phwt.de. The certificate seems to have been signed by SwissSign AG, to make it work you have these options:


  1. 安装颁发者的适当证书( SwissSign )。

  2. 添加以上证书或 www.phwt.de 的证书,以使受信任的证书颤抖/飞镖列表(更多信息此处此处):

  1. Install the issuer's appropriate certificate (SwissSign) system-wide (this is OS specific).
  2. Either add the above certificates or www.phwt.de's certificate to flutter/dart list's of trusted certificates (more info here and here):



SecurityContext clientContext = new SecurityContext()
    ..setTrustedCertificates(file: 'my_trusted_certificates.pem');
var client = new HttpClient(context: clientContext);
var request = await client.getUrl(Uri.parse("https://www.phwt.de"));
var response = await request.close();




  1. 通过设置信任代码本身中的证书回调到 client.badCertificateCallback 并检查签名是否匹配(请参阅这里

  2. 与3相同,但您不检查任何内容,只返回 true ,有效地使世界上任何证书都有效(这很危险)。

  1. Trust the certificate in the code itself by setting a callback to client.badCertificateCallback and checking if the signature matches (see here)
  2. Same as 3 but you don't check anything and just return true, effectively making any certificate in the world valid (this is potentially dangerous).

这篇关于Flutter中的HTTP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆