在c#当中使用httpclient发送http请求,代码如下:
string customTableServiceUrl = "https://localhost:5001/api/XXX/";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete,
customTableServiceUrl + "CLEVER/entries/2006");
var apiResponse = await httpClient.SendAsync(request);
但是在执行的时候却报错如下:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
在定义HttpClient的代码前加上一行代码解决了我的问题:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };