如何修复“未验证主机名music.wandhi.com”

时间:2019-07-04 14:22:39

标签: c# httpclient

我尝试使用HttpClient发布请求,但始终有一个错误: 主机名music.wandhi.com未验证:

certificate: sha1/EIlpvk5rW1fI2TT1KF9blPRGQD8=
DN: CN=cdn.wandhi.com
subjectAltNames: [cdn.wandhi.com]

我尝试添加代码"ServicePointManager.ServerCertificateValidationCallback +=(sender, cert, chain, sslPolicyErrors) => { return true; };" 里面,但是没有用。 提前非常感谢!

using (HttpClient client=new HttpClient())
            {
                client.BaseAddress = new Uri("https://music.wandhi.com/");           
                client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                client.Timeout = TimeSpan.FromSeconds(5);


                using (HttpRequestMessage requent = new HttpRequestMessage(HttpMethod.Post,client.BaseAddress))
                {
                    requent.Content = new StringContent(
                        string.Format("input={0}&filter=name&type={1}&page={2}",searchName,sourceType.ToString(),pagNum.ToString()),
                        Encoding.UTF8,
                        "application/x-www-form-urlencoded");

                    try
                    {
                        var response = client.SendAsync(requent).Result;
                        if (response.StatusCode== System.Net.HttpStatusCode.OK)
                        {
                            return response.Content.ReadAsStringAsync().Result;
                        }
                        else
                        {
                            return "error";
                        }
                    }
                    catch (HttpRequestException e)
                    {
                        return e.Message;
                    }
                }

            }

0 个答案:

没有答案