【问题标题】:Using Open Weather Map which is HTTP only through an HTTPS website and NOT get mixed content warning仅通过 HTTPS 网站使用 HTTP 开放天气地图,不会收到混合内容警告
【发布时间】:2014-09-10 19:16:56
【问题描述】:

我在这里查看了这个链接:Dealing with HTTP content in HTTPS pages

我从这里尝试了有关开放协议的方法:http://benpowell.org/https-and-http-the-protocol-less-or-protocol-relative-urls/

但我只有一次调用 openweathermap 的 HTTP url,它不会通过 HTTPS 提供其内容,除非您每月支付 500 美元。做不到。

所以,我需要找到一种方法来为 OpenWeatherMap 引入 HTTP 内容,而不是在“任何”浏览器上生成“混合内容”错误消息。

这里是 OWM 的 API 调用:http://api.openweathermap.org/data/2.5/weather?lat=32.22&lon=-100.50&APPID=c6fdcf2d49a0bba3e14f310bd3d5cdc2

有什么想法吗?

谢谢,提前。

【问题讨论】:

    标签: http ssl https


    【解决方案1】:

    在尝试使用 Open Weather Map API 将我的应用程序托管在 heroku 上时偶然发现了这个线程。

    把这个放在url前面:

    https://cors-anywhere.herokuapp.com/

    这样url就变成了

    https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/forecast? appid=${API_KEY}

    再次检查您的应用程序并注意 openweather 网址又是 http(原来的方式)!这个解决方案对我有用,虽然 CORS 解决方案可能不会永远持续下去。

    【讨论】:

      【解决方案2】:

      我能够让 api 加载到我的网站上,该网站使用一点 php 来强制执行 https。

      基本上,我将 http 站点卷曲并将结果存储在我的域上的一个页面上,该页面是 https,因此它非常适合我。

      我写了一个小函数来为我完成这项工作

       <?php
      #Defining the basic cURL function
          function curl($url) {
          $ch = curl_init();  // Initialising cURL
      #Setting cURL's URL option with the $url variable passed into the function
          curl_setopt($ch, CURLOPT_URL, $url);
      #Setting cURL's option to return the webpage data   
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
      #Executing the cURL request and assigning the returned data to the $data variable
          $data = curl_exec($ch); 
      #Closing cURL 
          curl_close($ch); 
      #Returning the data from the function  
          return $data;  
       }
           echo $scraped_website = curl("http://www.example.com");
      
      #I use http://api.openweathermap.org/data//2.5/weather?q=Saint+Louis%2C+MO&units=imperial&lang=nl&APPID=b923732c614593659457d8f33fb0d6fd&cnt=6 instead of "http://www.example.com"
      
      ?>
      

      #Full sn-p

           <?php
           // Defining the basic cURL function
          function curl($url) {
          $ch = curl_init();  // Initialising cURL
          curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
          $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
          curl_close($ch);    // Closing cURL
          return $data;   // Returning the data from the function
            }
           echo $scraped_website = curl("http://www.example.com");
           ?>
      
      
      
      enter code here
      

      【讨论】:

        【解决方案3】:

        由于 Forecast.io 更改为 Dark Sky 并且他们不允许 CORS,从而迫使您实现服务器端应用程序,因此我寻找适合小型前端项目的不同解决方案。

        我找到了apixu.com,它似乎更适合像我这样的简单目的:FreeCodeCamp 项目。

        它们同时提供 http 和 https 调用。您每月可免费获得 5000 次通话。

        【讨论】:

          猜你喜欢
          • 2018-02-18
          • 2018-09-11
          • 2018-12-19
          • 2017-02-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-08-03
          相关资源
          最近更新 更多