Hi:
I am using dataminer 9.5.
One of my devices is using self-signed certificate https restful API.
I need to POST first to https://url/login to get the token. Then i can GET from restful API.
In dataminer 9.5 driver development, is there a way that we can setup something like:
curl --insecure POST -H "Content-Type: application/json" -d DATA
The important is: how to let dataminer driver to ignore the self-signed certificate and continue?
Thanks
Hi Miao,
You can let a QAction in the driver execute the HTTP calls and disable the certificate validation. See this code snippet below, the bold part will disable the certificate validation. More information can be found in the MS docs.
var handler = new HttpClientHandler();
// Disable certificate validation
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;HttpClient client = new HttpClient(handler);
var response = client.PostAsync(...);
Hi Miao, the code above will indeed only work on .NET 4.6.2 or higher. On servers that do not run this version you have several other options. First I would consider if you can trust the certificate of the REST API in the Certificate Store of the Windows server hosting DataMiner. If that is not possible, you can try this solution: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5359#solution
It will only disable the certificate validation for specific URLs or requests. That way you’re not globally disabling it, but for example only for that specific REST API.
If possible you can also consider upgrading your .NET version to a version that supports the newer syntax.
I hope this helps!
Hi Jen:
Thank you very much for the response. My dataminer server’s .NET framework is 4.0. It doesn’t have the httpClient installed. So i guess i need to use webRequest? How to make webRequest accept self-signed certificate?
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; It can do the work but seems it changes the GLOBAL security settings. That’s not applicable in PROD server. Anyway we could install HttpClient in .NET 4.0 dataminer server?
Thanks