如何在Chrome扩展中发送HTTP GET请求? [英] How do I send an HTTP GET request in chrome extension?

查看:1762
本文介绍了如何在Chrome扩展中发送HTTP GET请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究使用GET方法发送HTTP请求的chrome扩展。



如何在 www.example .com 参数参数 0

  www.example.com?par=0 

(服务器读取参数 par 并做了一些工作)



我发现了这篇文章,关于跨源XMLHttpRequest 。但我不知道他们的例子如何帮助我。

并添加 www.example.com 的权限:

<$ p $ {
name:我的扩展名,
...
权限:[
http://www.example .com / *

...
}

然后在你的后台页面(或其他地方)你可以这样做:

  var xhr = new XMLHttpRequest(); 

xhr.open(GET,http://www.example.com?par=0,false);
xhr.send();

var result = xhr.responseText;






有关此主题的更多信息,请参阅相关 文档页


I'm working on a chrome extension that send an HTTP request using the method GET.

How do I send at www.example.com the parameter par with value 0?

www.example.com?par=0

(the server reads the parameter par and does some stuff)

I found this article, talking about Cross-Origin XMLHttpRequest. But I don't know how their example could help me.

解决方案

You have to go to your manifest.json and add the permission for www.example.com:

{
    "name": "My extension",
    ...
    "permissions": [
        "http://www.example.com/*"
    ],
    ...
}

Then in your background page (or somewhere else) you can do:

var xhr = new XMLHttpRequest();

xhr.open("GET", "http://www.example.com?par=0", false);
xhr.send();

var result = xhr.responseText;


For more information on this topic, see the relative documentation page.

这篇关于如何在Chrome扩展中发送HTTP GET请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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