0

I have a JSON which contains "judul" and "cover". The "cover" contains untrusted SSL, while JSON does not. Code:

string certPath = @"Assets\kcssl.p12";
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(certPath);
IBuffer buffer = await FileIO.ReadBufferAsync(file);
string certData = CryptographicBuffer.EncodeToBase64String(buffer);
await CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync(
    certData, "Asdf123#", ExportOption.NotExportable, KeyProtectionLevel.NoConsent,
                                InstallOptions.None, "kcssl");
var certificate = await CertificateStores.FindAllAsync(new CertificateQuery() { FriendlyName = "kcssl" });
ClientCert = certificate.Single();
HttpBaseProtocolFilter aHBPF = new HttpBaseProtocolFilter();
aHBPF.ClientCertificate = ClientCert;
HttpClient httpClient = new HttpClient(aHBPF);
Dictionary<string, string> pairs = new Dictionary<string, string>();
pairs.Add("halaman", "1");
pairs.Add("limit", "16");
pairs.Add("SCH-API-KEY", "SCH_KEnaBiDeplebt");
var formContent = new HttpFormUrlEncodedContent(pairs);
HttpResponseMessage response = await httpClient.PostAsync(new Uri(urlPath), formContent);
httpClient.Dispose();
response.EnsureSuccessStatusCode();
string jsonText = await response.Content.ReadAsStringAsync();
try
{
    JsonArray jsonData1 = jsonObject["data"].GetArray();
    foreach (JsonValue groupValue1 in jsonData1)
    {
        JsonObject groupObject2 = groupValue1.GetObject();  
        string title = groupObject2["judul"].GetString();
        string cover = groupObject2["cover"].GetString();
        Buku file1 = new Buku();
        file1.Judul = title;
        string thumb = cover.Replace("http://", "https://");
        file1.Cover = thumb;
    }
    itemGridView.ItemsSource = datasource;
}

I have a problem, which is unable to display the cover on the gridview ("cover" is blank). How to handle it?

Rose
  • 613
  • 4
  • 22
  • You could use [HttpClientHandler.ServerCertificateCustomValidationCallback](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.servercertificatecustomvalidationcallback?view=net-5.0) method to add a certificate validation handler, which returns true will allow ignoring the validation error. More info could be found [here](https://stackoverflow.com/questions/2675133/c-sharp-ignore-certificate-errors). – dear_vv Feb 03 '21 at 06:28
  • I've tried changing it to ```httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => { ... }``` but the cover is still blank – Rose Feb 05 '21 at 02:07
  • Could you please confirm whether the value of ‘cover’ is correct? I suggest you use the Postman tool to test whether the value of ‘cover’ has been obtained. – dear_vv Feb 05 '21 at 09:53

0 Answers0