Flutter 中的 HTTP 响应
HTTP-Response in Flutter
我对颤振有疑问。我想从网站获取 HTTP 响应,但它不起作用。该示例适用于其他网站,但不适用于所需的网站。
代码:
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 签署,要使其正常工作,您可以选择以下选项:
- 在系统范围内安装颁发者的适当证书 (SwissSign)(这是 OS 特定的)。
- 将上述证书或
www.phwt.de
的证书添加到 flutter/dart 受信任证书列表(更多信息 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();
- 通过将回调设置为
client.badCertificateCallback
并检查签名是否匹配(请参阅 here)来信任代码本身的证书
- 与 3 相同,但您不检查任何内容,只是 return
true
,有效地使世界上的任何证书都有效(这有潜在的危险)。
我对颤振有疑问。我想从网站获取 HTTP 响应,但它不起作用。该示例适用于其他网站,但不适用于所需的网站。 代码:
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 签署,要使其正常工作,您可以选择以下选项:
- 在系统范围内安装颁发者的适当证书 (SwissSign)(这是 OS 特定的)。
- 将上述证书或
www.phwt.de
的证书添加到 flutter/dart 受信任证书列表(更多信息 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();
- 通过将回调设置为
client.badCertificateCallback
并检查签名是否匹配(请参阅 here)来信任代码本身的证书 - 与 3 相同,但您不检查任何内容,只是 return
true
,有效地使世界上的任何证书都有效(这有潜在的危险)。