我正在尝试在我正在创建的ASP.NET Web API的Controller中调用第三方api。下面是代码
public string Get(string Name)
{
using (var client = new HttpClient())
{
string BaseURL = ConfigurationManager.AppSettings["BaseURL"];
Uri uri = new Uri(BaseURL);
client.BaseAddress = uri;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
string clarity_URL = BaseURL+"api/v2/hhgh?name="+Name;
var response = client.GetAsync(c_URL).Result;
string responseString;
if (response.IsSuccessStatusCode)
{
responseString = response.Content.ReadAsStringAsync().Result;
}
return responseString;
我在var response = client.GetAsync(clarity_URL).Result;
中收到System.AggregateException
当我扩展InnerException
时 {"An error occurred while sending the request."}
{"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."}
{"The remote certificate is invalid according to the validation procedure."}