I'm accessing an internal database using MATLAB's urlread
command, everything was working fine until the service was moved to a secure server (i.e. with an HTTPS address rather than an HTTP address). Now urlread
no longer successfully retrieves results. It gives an error:
Error downloading URL. Your network connection may be down or your proxy settings improperly configured.
I believe the problem is that the service is using an invalid digital certificate since if I try to access the resource directly in a web browser I get "untrusted connection" warning which I am able to pass through by adding the site to an Exception list. urlread
doesn't have an obvious way of handling this problem.
Under the hood urlread
is using Java to access web resources, and the error is thrown at this line:
inputStream = urlConnection.getInputStream;
where urlConnection
is a Java object: sun.net.www.protocol.https.HttpsURLConnectionImpl
.
Anyone suggest a workaround for this problem?
Consider the following Java class. I used this page as reference:
C:\MATLAB\MyJavaClasses\com\stackoverflow\Downloader.java
MATLAB
First we compile the Java class (we must use a JDK version compatible with MATLAB):
Next we instantiate and use it MATLAB as:
Here are a few URLs with bad SSL certificates to test:
UPDATE: I should mention that starting with R2014b, MATLAB has a new function
webread
that supersedesurlread
.Note also that the "canonical" way to solve this issue is to import the certificate into MATLAB's keystore (i.e., not your JVM's keystore).
This is documented here: Mathworks on using untrusted SSL certificates.
thanks for the solution. It worked, however, sometimes, I had received the following exception "java.io.IOException: The issuer can not be found in the trusted CA list." and I was not able to get rid of this error.
Therefore, I tried an alternative solution that works well. You can use the following Java code in Matlab function:
Best, Jan