如何在超级代理的GET请求中添加头信息?

问题描述 投票:0回答:0

这是一个基本的代码。

const superagent = require('superagent');

superagent.get('https://api.arabam.com/pp/step')
.query({ apikey: '_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA==' })
.end((err, res) => {
  if (err) { return console.log(err); }
  console.log(res.body.url);
  console.log(res.body.explanation);
});

但apikey是头而不是查询。我如何将其作为头文件发送?

编辑:我试过使用请求模块,它只是说我无法访问它。

我试过用请求模块,但它只是说我无法访问它。

var request = require("request");

request({
  uri: "https://api.arabam.com/pp/step",
  method: "GET",
  'Content-Type' : "application/json",
  apikey: "_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA=="
}, function(error, response, body) {
  console.log(body);
});

它说未经授权访问

node.js http get superagent
© www.soinside.com 2019 - 2024. All rights reserved.