I'm trying to use URL Fetch API to make Https requests to my backend service.
I'm using HttpsURLConnection because my backend is using a self-signed certificate and I need to validate that certificate as trusted.
This snippet
...
URL url = new URL("https://example.com/api");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(sslContext.getSocketFactory());
throws
java.lang.ClassCastException: com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection cannot be cast to javax.net.ssl.HttpsURLConnection
I know that App Engine employs its own handler for url.openConnection()
which returns a sibling to HttpsURLConenction
, which is why the cast fails.
Is there a way for me to use HttpsURLConnection with URLfetch? Are there other options to connect to my backend via Https?