client.GetAsync

时间:2016-12-22 21:27:54

标签: c# asp.net asp.net-mvc api asp.net-web-api

我正在尝试在我正在创建的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

的错误

enter image description here

当我扩展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."}

0 个答案:

没有答案