简体   繁体   English

在Firefox插件中发送POST请求(javascript)

[英]Sending POST request in firefox addon (javascript)

With a firefox addon (javascript) I'm trying to send a POST request to a server to get a session ID back, but none of conventional methods seem to work, I already tried xmlhttprequest and getting it with forms isn't possible because it's internal code. 我使用firefox插件(javascript)尝试将POST请求发送到服务器以获取会话ID,但是似乎所有常规方法都不起作用,我已经尝试过xmlhttprequest,并且无法通过表单获取它,因为内部代码。 Is there a way to get this working, maybe even with the addon SDK? 是否有办法使此工作正常进行,甚至使用插件SDK也可以吗?

References to my tries: 我的尝试参考:

Javascript sending data via POST in firefox addon Javascript在Firefox插件中通过POST发送数据

HTTP POST in javascript in Firefox Extension Firefox扩展中javascript中的HTTP POST

With the new Addon SDK you should use the new Request API instead of XMLHttpRequest. 使用新的Addon SDK,您应该使用新的Request API而不是XMLHttpRequest。 The new Interface is a lot easier to use, too. 新界面也更易于使用。

Here is a quick example: 这是一个简单的示例:

// make sure this gets executed BEFORE making the Request
var Request = require("sdk/request").Request;

Request({
  url: "http://example.com/hello-world.php",
  content: { hello: 'world' },
  onComplete: function (response) {
    console.log( response.text );
  }
}).post();

I suggest you may have a look at this MDN Tutorial: Getting started 我建议您可以看看此MDN教程: 入门

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM