0

我现在要做的就是记录我试图通过 POST 调用从 Sky Scanner API 检索的数据,但我收到错误 500。关于我在这里做错了什么有什么想法吗?

顺便说一句,新程序员

更新:错误 400

const KEY = '123';

fetch("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0", {
	"method": "POST",
	"headers": {
		"x-rapidapi-host": "skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
		"x-rapidapi-key": `${KEY}`,
		"content-type": "application/x-www-form-urlencoded"
	},
	body: new URLSearchParams({
		"inboundDate": "2019-11-10",
		"cabinClass": "business",
		"children": "0",
		"infants": "0",
		"country": "US",
		"currency": "USD",
		"locale": "en-US",
		"originPlace": "SFO-sky",
		"destinationPlace": "LHR-sky",
		"outboundDate": "2019-11-20",
		"adults": "1"
	  })
})
.then(response => {
	console.log(response);
})
.catch(err => {
	console.log(err);
});

4

1 回答 1

0

您不需要将 API 密钥作为文字字符串传递。

像这样传递它:

"x-rapidapi-key": KEY,

PS 使用环境变量传递 API 密钥,因为这是一个敏感的凭证。

于 2021-09-24T21:04:19.870 回答