【发布时间】:2021-03-11 19:21:38
【问题描述】:
我正在尝试使用 nodeJS 请求库发出 POST 请求以清除与某个 surrogate key via Fastly API 关联的内容。 POST 请求看起来像这样:
POST /service/SU1Z0isxPaozGVKXdv0eY/purge
Content-Type: application/json
Accept: application/json
Fastly-Key: YOUR_FASTLY_TOKEN
Fastly-Soft-Purge: 1
Surrogate-Key: key_1 key_2 key_3
我尝试在 node.JS 中以两种不同的方式做到这一点。
第一个:
// perform request to purge
request({
method: `POST`,
url: `/service/${fastly_service_id}/purge${surrogateKeyArray[i]}`,
headers: headers,
}, function(err, response, body) {
// url was not valid to purge
if (err) {
console.log("is there an err???")
console.log(err)
}
})
}
我明白了,Error: Invalid URI: /service/<fastly_Service_id>/purge/<surrogate_key>
我通过curl -s -I -H "Fastly-Debug: 1" <URL corresponding to surrogate key> | grep surrogate-key仔细检查了我的代理键
它返回我的代码中使用的相同代理键。
在第二次尝试中,我尝试了:
// perform request to purge
request({
method: `POST /service/${fastly_service_id}/purge${surrogateKeyArray[i]}`,
headers: headers,
}, function(err, response, body) {
// url was not valid to purge
if (err) {
console.log("is there an err???")
console.log(err)
}
})
}
我得到了错误,Error: options.uri is a required argument
【问题讨论】:
标签: node.js request http-post fastly