无法加载资源:net::ERR_CONNECTION_REFUSED 仅适用于来自 instagram API 的选择性



我目前正在向 instagram API 发出GET请求,以获取一堆带有特定标签的照片,并将我在 Rails 中获得的 JSON 对象返回给 JS 中的调用者,并在 DOM 中使用 img 链接和缩略图等设置 HTML。

奇怪的是,重新启动服务器后,我收到此错误:

Failed to load resource: net::ERR_CONNECTION_REFUSED 

仅适用于Instagram API返回的部分但不是全部照片。

  var formdata = {tag: "myflsadventure"};
 $.ajax({
    url: "application/get_instagram_photos",
    type: "POST",
    datatype: 'json',
    data: formdata,
    success: function(response){
     htmlz = "<div class='container'><div class='row'>";
      count = 0;
      rounded_style = " style='border:1px solid #; -webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;'"
      $.each(response.data, function(i, item) {
        if (count == 0 ){
          htmlz += "<div class='col-md-6'><img src='"+item.images.standard_resolution.url+ "'" + rounded_style+"></div><div class='col-md-6'><div class='no-top'>";
          count = count + 1;
        }
        else if (count == 9){
          htmlz += "</div><div class='row'><div class='col-md-6'><div class='no-top'><div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url+ "'" + rounded_style + "></div>";
          count = count + 1;
         }
        else if (count == 13){
          htmlz += "<div class='col-md-6'><img src='" + item.images.standard_resolution.url+ "'" + rounded_style + "></div></div></div>";
         count = count + 1;
         }
        else if (count ==5){
           htmlz += "</div><div class='row'><div class='col-md-3'><img src='" +item.images.low_resolution.url+ "'" +rounded_style+ "></div>";
          count = count + 1;
        }
         else if ((count == 4) || (count == 12)){
           htmlz += "<div class='col-md-6'><img src='"+item.images.low_resolution.url+ "'" + rounded_style +"></div></div></div></div></div>";
           count = count + 1;
        }
        else if ((count == 6)  || (count == 7) || (count == 8)  ){
           htmlz += "<div class='col-md-3'><img src='"+ item.images.low_resolution.url+ "'" + rounded_style + "></div>";
           count = count + 1;
         }
        else if ((count == 3) || (count == 11)){
           htmlz += "<div class='top'><div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url + "'" + rounded_style + " ></div>";
           count = count + 1;
        }
         else if ( count == 1){
           htmlz += "<div class='row'><div class='col-md-6'><img src='" + item.images.low_resolution.url + "'" + rounded_style + " ></div>";
           count = count + 1;
        }
        else{
           htmlz += "<div class='col-md-6'><img src='"+ item.images.low_resolution.url+ "'"+ rounded_style + "></div></div>";
          count = count + 1;
        }
      });
       $("#myflsadventure").append(htmlz);
       reapportion_les_fotos();
    }
    });

这是我的路由,最后是我的控制器,它进行 API 调用

  post '/application/get_instagram_photos', to: 'school_applications#get_instagram_photos'

控制器方法

  def get_instagram_photos
respond_to do |format|
  uri = URI("https://api.instagram.com/v1/tags/#{params[:tag]}/media/recent?client_id=myIDc&count=14")
  response = Net::HTTP.get(uri)
  format.json {render :json => response}
end

结束

更新:

这只发生在我的开发机器上。推送到 Heroku 并从其他计算机查看后,除了仍在我的主工作机器上外,照片加载正常。它似乎独立于浏览器(尝试过Opera,Firefox,Safari和Chrome)和广告拦截独立(根据类似SO帖子中的建议在Chrome隐身上尝试过)。

我在开发机器上也有类似的行为,在编辑重定向.htaccess后会出现错误消息。我无法再从同一网络中任何设备上的任何浏览器访问特定网站(尽管我能够通过某些 shell 命令访问它)。我强烈认为我的路由器存在安全问题,并阻止了浏览器对网站的进一步访问。大约 24 小时后,我能够再次访问该网站。

现在这个问题已经被问了一段时间了,所以我不会要求你设置相同的环境来测试你是否也有 24 小时的阈值并进一步澄清这个问题。

编辑:这是我尝试仅在浏览器中ERR_CONNECTION_REFUSED解决问题的问题的链接

最新更新