从chrome扩展发送https到http的请求 [英] sending request from https to http from chrome extension

查看:1461
本文介绍了从chrome扩展发送https到http的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个奇怪的问题,从https站点发送到http站点的请求由谷歌浏览器扩展..

Hello all i am having a strange issue with sending a request from https site to http site by google chrome extension..


jquery .js:6个混合内容: https://www.google.co。 in / webhp?hl = en '是通过HTTPS加载的,但请求一个不安全的XMLHttpRequest端点' http:// IP /统计/ search.php中?关键字=苹果。此请求已被阻止;该内容必须通过HTTPS提供。

jquery.js:6 Mixed Content: The page at 'https://www.google.co.in/webhp?hl=en' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://ip/stats/search.php?keywords=apple'. This request has been blocked; the content must be served over HTTPS.

这是我的代码,它被注入到网站...

this is my code which is injected to the site ...

  $(document).ready(function(){
    $('input[name=q]').keydown(function(e) {
        if (e.keyCode == 13) {
            v = $(this).val();
            v=encodeURI(v);
        $.ajax({
        type: 'POST',
        url: 'http://myipaddress/stats/search.php?keywords='+v,
        data:{'search':v},
        success: function(data){ 
        //something....
        }   
        });
           }


  }); 
  });

Manifest.json

Manifest.json

   {
  "name": "Ads",
  "version": "0.0.1",
  "manifest_version": 2,
   "description": "Injecting stuff",

      "background":
         {
         "scripts": ["jquery.js","background.js"]
              },
          "browser_action": {
        "default_title": "Inject!"
          },
         "permissions": [
        "https://*/*",
         "http://*/*",
         "tabs"
        ],"content_scripts" : [
         {
       "js": ["jquery.js", "inject.js"],
           "matches": ["*://*/*"]
      }
       ]
       }


推荐答案

如果由于页面原点而无法从内容脚本发出请求,请将其委托给后台脚本。

If you can't make a request from the content script due to the page's origin, delegate that to the background script.

发送消息到后台脚本以指示它发出请求,然后返回响应。记得从处理程序中返回返回true ,以表明您将以异步方式响应。

Send a message to the background script to instruct it to make a request, then return the response. Remember to return true from the handler to indicate that you will respond asynchronously.

这篇关于从chrome扩展发送https到http的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆