在响应 AdRequest 时强制 HTTP 协议为 HTTPS

Force HTTP protocol to HTTPS on response to AdRequest

如何以及在何处可以将我为我的(发布者)Adview 获得的响应的 HTTP 协议从 HTTP 更改为 HTTPS? 这使我的 adview 能够显示来自第三方网络的广告,这些广告现在被阻止了。 我已经联系了 Google 移动广告 SDK 支持团队,他们的回答是在广告请求响应的 HTTP 协议中添加一个 S 可以显示广告。 但是我找不到在哪里以及如何执行此操作。

下面是我在 logcat 中收到的错误:

10-23 19:56:15.813 18492-18492/com.koeck.verdienapp W/chromium: [WARNING:web_contents_impl.cc(2990)] https://pubads.g.doubleclick.net ran insecure content from http://ib.adnxs.com/ttj?id=4433225&size=300x250&referrer=com.koeck.android&cb=774743058&psa=false&position=above 10-23 19:56:15.823 18492-18492/com.koeck.verdienapp W/chromium: [WARNING:web_contents_impl.cc(2990)] https://.. ran insecure content from http://.. 10-23 19:56:15.823 18492-18492/com.koeck.verdienapp W/Ads: JS: Mixed Content: The page at 'https://..' was loaded over HTTPS, but requested an insecure script

到目前为止,我已经想出了将 HTTP 更改为 HTTPS 的代码:

public void changeHTTP(URL url) throws IOException {
            if ("http".equals(url.getProtocol())) {
                String urlSource = "";

            try {
                urlSource = URLDecoder.decode(url, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace(); // This should not happen.
            }

            Log.d(TAG, "decoded: " + urlSource);

            String urlNew = urlSource.replace("http","https");
            }
    }

感谢您花时间阅读我的问题。

亲切的问候, 罗吉尔范登布林克

它比你想象的更容易:

public URL changeHTTP(URL url) throws IOException {
     String strUrl = url.toString();
     if (strUrl.indexOf("http://", 0) == 0)
     {
         strUrl = strUrl.replace("http://", "https://");
         url = new URL(strUrl);
     }
     return url;
}