小编ess*_*xiv的帖子

带有标头的节点获取 API GET

https://www.npmjs.com/package/node-fetch Node v6.4.0 npm v3.10.3

我想在此 API 调用中发送带有自定义标头的 GET 请求。

const fetch = require('node-fetch')
var server = 'https://example.net/information_submitted/'

var loginInformation = {
    username: "example@example.com",
    password: "examplePassword",
    ApiKey: "0000-0000-00-000-0000-0"
}

var headers = {}
headers['This-Api-Header-Custom'] = {
    Username: loginInformation.username,
    Password: loginInformation.password,
    requiredApiKey: loginInformation.ApiKey
}

fetch(server, { method: 'GET', headers: headers})
.then((res) => {
    console.log(res)
    return res.json()
})
.then((json) => {
    console.log(json)
})
Run Code Online (Sandbox Code Playgroud)

标题不适用,我被拒绝访问。但是在 curl 命令中,它可以完美运行。

api node.js

11
推荐指数
2
解决办法
4万
查看次数

标签 统计

api ×1

node.js ×1