我想接受不受信任的自签名证书。我无法找到使用 http-package 执行此操作的方法。
有人可以帮我修改下面的代码以接受自签名证书吗
import 'package:http/http.dart' show Client, Response;
import 'dart:convert';
final Client _client = Client();
Future<dynamic> postRequest(User user, String uri, String postBody,
{decode: true}) async {
try {
var url = user.protocol + '://' + user.hostname + ':' + user.port + uri;
String basicAuth =
'Basic ' + base64Encode(utf8.encode('${user.username}:${user.password}'));
var appHeaders = {
'authorization': basicAuth,
"Content-Type": "application/xml",
"Accept": "application/json"
};
String resBody = await _client
.post(url, body: postBody, headers: appHeaders)
.then((Response res) => res.body);
if (decode) {
return json.decode(resBody);
} else {
return resBody;
}
} catch (e) {
return e;
}
}