【问题标题】:How do I make a post request in node using parse server?如何使用解析服务器在节点中发出发布请求?
【发布时间】:2016-10-06 04:34:19
【问题描述】:

我正在使用 api 做一些工作,我需要向我的解析服务器发出一个 post 请求,但我收到错误 error:{unauthorized access},我很确定这是因为密钥,但我不确定。我正在使用邮递员查看是否可以向 app.post 函数发出请求,但出现上述错误。我正在向`https://xxxxxxxx.herokuapp.com/parse/index/testing提出请求

var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

app.get('/', function(req, res) {
 res.status(200).send('I dream of being a website.  Please star the parse-  server repo on GitHub!');
});


app.post('/testing', twilio.webhook({ validate: false }), headers: {"AppId": "", "MasterKey": ""}, function (req, res) {
   console.log("testing")

});

Heroku 日志

at=info method=POST path="/parse/index/testing" host=xxxxxxx.herokuapp.com request_id=..... fwd="xx.xxx.xxx.xxx" dyno=web.1 connect=1ms service=41ms status=403 bytes=506

【问题讨论】:

  • 你能运行heroku logs看看发生了什么
  • @abdulbarik 我更新了我的问题以包含日志
  • statusCode=403 : 你没有权限访问这个资源
  • 是的,这就是我的想法,但是如何将密钥附加到请求中?
  • 意思是你想在这条路线上附加app.post('/testing')?

标签: node.js http-post httprequest parse-server


【解决方案1】:

尝试像这样附加你master key

app.post('/testing/masterkey/:masterkey', twilio.webhook({ validate: false }), function (req, res) {
   console.log("testing")
console.log(req.params.masterkey);
});

并以这种格式请求

hostname/testing/masterkey/1234

编辑

邮递员发来的电话

【讨论】:

  • 我厌倦了像 '/testing/Parse-Master-Key/xxxxxxxxxxxx' 以及你提出的方式,但我得到了同样的错误
  • 你能拿到钥匙吗?
  • 什么意思?
  • 撒谎,如果您期待主密钥,那么您必须在任何地方使用它?
  • 我发现这个有用的链接说我必须在请求标头中添加主密钥和应用程序 ID,但不确定如何在代码中添加标头。 github.com/ParsePlatform/parse-server/issues/1657
猜你喜欢
  • 2018-01-26
  • 2019-04-08
  • 2019-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-09
  • 2020-03-29
相关资源
最近更新 更多