2021年1月18日星期一

Bypass Untrusted SSL in localhost link

I have a localhost link containing json to display. I have a problem, namely I can't show the cover because the link is ssl untrusted. Code:

using (var httpClientHandler = new HttpClientHandler())                              {                                  httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => {                                      if (sslPolicyErrors == SslPolicyErrors.None)                                      {                                          return true;   //Is valid                                      }                                      if (cert.GetCertHashString() == "ba36ef4d9f6223ce168499eb8314dd1015e90de2")                                      {                                          return true;                                      }                                      return false;                                  };                                  using (var httpClient = new HttpClient(httpClientHandler))                                  {  var values = new List<KeyValuePair<string, string>>                              {                                  new KeyValuePair<string, string>("halaman", offset.ToString()),                                  new KeyValuePair<string, string>("limit", "16"),                                  new KeyValuePair<string, string>("SCH-API-KEY", "SCH_KEnaBiDeplebt")                              };                                      var response = await httpClient.PostAsync(urlPath, new FormUrlEncodedContent(values));                                      response.EnsureSuccessStatusCode();                                      if (!response.IsSuccessStatusCode)                                      {                                          busyindicator.IsActive = false;                                          RequestException();                                          loading.Visibility = Visibility.Collapsed;                                      }                                      string jsonText = await response.Content.ReadAsStringAsync();                                      try                                      {                                          JsonObject jsonObject = JsonObject.Parse(jsonText);                                          JsonArray jsonData1 = jsonObject["data"].GetArray();                                          foreach (JsonValue groupValue1 in jsonData1)                                          {                                              JsonObject groupObject2 = groupValue1.GetObject();                                              string id = groupObject2["id"].GetString();                                              string cover = groupObject2["cover"].GetString();                                                Buku file1 = new Buku();                                              file1.ID = id;                                              string thumb = cover.Replace("http://", "https://");                                              file1.Cover = thumb;  datasource.Add(file1);  itemGridView.ItemsSource = datasource;  

I have added the certificate to the declaration, as shown below: certificate

https://stackoverflow.com/questions/65784626/bypass-untrusted-ssl-in-localhost-link January 19, 2021 at 10:14AM

没有评论:

发表评论