我试图使用nodeJS请求库发出POST请求,以清除与特定通过快速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
发布于 2021-03-15 09:11:42
我不熟悉节点和成功发出HTTP请求所涉及的代码,但从我可以看到的代码中可以看到,如果您提供的代码似乎与您没有提供完全限定的域有关(例如,您在路径之前缺少了https://api.fastly.com )。
当然,除非这是在代码的其他地方配置的,而且在这里是不可见的。
还要确保在/purge和${surrogateKeyArray[i]}之间包含一个/分隔符(我在下面的示例代码中显示了这一点)。
因此,考虑到这一点,我建议尝试:
request({
method: `POST`,
url: `https://api.fastly.com/service/${fastly_service_id}/purge/${surrogateKeyArray[i]}`,
headers: headers,
}, function(err, response, body) {
if (err) {
console.log(err)
}
})
}https://stackoverflow.com/questions/66589147
复制相似问题