[UWP][C#] Cannot display cover in gridview with untrusted ssl link

Rose 1 Reputation point
2021-03-02T04:25:18.99+00:00

I have a gridview which fetches data from json from localhost.
JSON:
73158-json.png

For 'cover' on json contains untrusted ssl
Code:

string certPath = @"Assets\kc-ssl.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;  
Create our http client and send the request.  
HttpClient httpClient = new HttpClient(aHBPF);  
Dictionary<string, string> pairs = new Dictionary<string, string>();  
pairs.Add("halaman", offset.ToString());  
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);  
string jsonText = await response.Content.ReadAsStringAsync();  
try  
{  
    JsonObject jsonObject = JsonObject.Parse(jsonText);  
        JsonObject groupObject1 = jsonObject.GetObject();  
    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;  
        file1.Cover = cover.Replace("http://", "https://");  
        datasource.Add(file1);  
    }  
    itemGridView.ItemsSource = datasource;  
}  

I have a problem, which is unable to display the cover (only blank), as shown below:
73169-gridview.png
How to handle it?

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Peter Smith 581 Reputation points Microsoft Employee
    2021-03-04T18:58:26.117+00:00

    FYI: the quickest way to get help here is to include the exact URL that you're trying to access. That way the problem can be reproduced with other tools (like curl, using UWP HttpClient, etc.)