如何在颤振中发布原始body数据并且没有 SSL 证书验证?



我正在颤振中使用 HTTP 包发送帖子请求,但它显示握手异常。 当我使用IOClient时,我解决了SSL验证问题,但我无法将原始数据发送到服务器

bool trustSelfSigned = true;
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => trustSelfSigned);
try {
IOClient ioClient = new IOClient(httpClient);
final response = await ioClient.post('${baseUrl}/register/phone', body:
{
'phone': '998$phone'
},
encoding: Encoding.getByName(name)
);
print('response ${response.body}');
}catch(e){
print(e);
}

将代码更新为:

final response = await ioClient.post('${baseUrl}/register/phone', body:
{
'phone': '998$phone'
}
,headers: {HttpHeaders.contentTypeHeader:'application/json'}
,encoding: Encoding.getByName(name)
);

最新更新