编程语言
首页 > 编程语言> > java – 用于HTTPS的GAE URL获取服务

java – 用于HTTPS的GAE URL获取服务

作者:互联网

我的应用程序抛出此错误:

[INFO] Caused by: java.lang.ClassCastException: com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection cannot be cast to javax.net.ssl.HttpsURLConnection
[INFO]  at info.modprobe.browserid.Verifier.verify(Verifier.java:76)

导致错误的代码是:

        URL verifierURL = new URL(this.url);
        String response = "";
        HttpsURLConnection connection = (HttpsURLConnection) verifierURL
                .openConnection(); // error here...
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type",
                "application/json; charset=utf-8");
        connection.setDoOutput(true);

尝试使用此library进行Mozilla个人验证时.我想知道自GAE URL Fetch Service支持HTTPS后可能出现的问题.

解决方法:

尝试

HttpURLConnection connection = (HttpURLConnection) verifierURL.openConnection();

代替

HttpsURLConnection connection = (HttpsURLConnection) verifierURL.openConnection();

它将创建它所需的内容,也适用于HTTPS,但不要强制转换为HttpS,因为它使用一个类(URLFetchServiceStreamHandler $Connection)taht扩展HttpURLConnection而不是HttpsURLConnection

标签:java,google-app-engine,urlfetch
来源: https://codeday.me/bug/20190623/1274875.html