【问题标题】:How can I correctly make this http request?我怎样才能正确地发出这个 http 请求?
【发布时间】:2016-11-29 18:00:11
【问题描述】:

最近我偶然发现了这个SimplePush.io,它非常适合我的项目,所以基本上它可以通过网站上的 curl 完美运行:

~ $ curl 'https://api.simplepush.io/send/HuxgBB/Wow/So easy'

~ $ curl --data 'key=HuxgBB&title=Wow&msg=So easy' https://api.simplepush.io/send

所以我试图在 NodeJS 上的服务器端应用程序中使用它,但我尝试了很多很多方法都没有成功..

所以我想知道是否有人可以帮助我用一些代码来完成这个。非常感谢提前

我不会发布我编写的任何代码,因为都是错误的,我不知道从哪里开始

【问题讨论】:

  • 下面的工作有效吗?

标签: javascript node.js http curl


【解决方案1】:

首先,安装 npm request 模块。

$ npm install request

然后在你的节点文件中:

var request = require('request');
request('https://api.simplepush.io/send/HuxgBB/Wow/So easy', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
})

【讨论】:

  • @FabioEnne 只是在node 中的一个简单的GET 请求。当你知道的时候很容易,从现在开始你就会:-)祝你无论做什么都好运
猜你喜欢
  • 2022-10-19
  • 2016-06-15
  • 2021-09-24
  • 2018-09-21
  • 1970-01-01
  • 1970-01-01
  • 2012-06-14
  • 1970-01-01
  • 2021-04-01
相关资源
最近更新 更多