我正在使用来自 dart 的 HttpClient(dart:io 包,而不是 dart:http),我想发送一个 HTTPS 请求。有没有办法做到这一点?我似乎找不到允许我这样做的方法。
问问题
5937 次
3 回答
3
new HttpClient().getUrl(Uri.parse('https://www.somedomain.com'));
于 2014-02-11T13:40:12.127 回答
0
发送 HTTPS 请求的步骤与 dart/flutter 中的 HTTP 相同,您必须添加的一件事是允许自签名证书处理 badCertificateCallback,将其添加到您的 HttpClient:
var httpClient = HttpClient();
httpClient.badCertificateCallback =
((X509Certificate cert, String host, int port) =>
true); // Allow self signed certificates
于 2020-04-09T13:18:48.327 回答
0
HttpClient client = new HttpClient();
client.getUrl(Uri.parse("http://www.example.com/"))
.then((HttpClientRequest request) {
// Optionally set up headers...
// Optionally write to the request object...
// Then call close.
...
return request.close();
})
.then((HttpClientResponse response) {
// Process the response.
...
});
参考: https ://api.dart.dev/stable/2.13.1/dart-io/HttpClient-class.html
于 2021-06-06T14:51:37.053 回答