要在AWS API Gateway的HTTP API中传递多个cookie,您可以使用以下解决方案:
以下是一个使用Node.js和AWS SDK的示例代码:
const AWS = require('aws-sdk');
const https = require('https');
exports.handler = async (event) => {
// 从API Gateway的事件中获取要发送的cookie
const cookies = event.headers['Cookie'];
const options = {
hostname: 'your-backend-api.com',
path: '/your-api-endpoint',
method: 'GET',
headers: {
// 设置其他必需的头部信息
'Content-Type': 'application/json',
// 将多个cookie放入一个头部中
'Cookie': cookies.join('; ')
}
};
// 发送HTTP请求
const response = await new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
resolve({
statusCode: res.statusCode,
body: body
});
});
});
req.on('error', (error) => {
reject(error);
});
req.end();
});
return response;
};
上述代码将从API Gateway事件中获取到的cookie数组连接为一个字符串,并将其设置为发送到后端API的HTTP请求头部中的Cookie头。您可以根据实际情况进行修改和调整。
请注意,上述代码仅为示例,您需要根据自己的需求进行适当的修改和错误处理。