POST请求后AWS API Gateway与Lambda重定向不生效问题求助
问题:POST请求返回303重定向后页面不跳转
我有一个以Lambda函数为后端的AWS API Gateway端点,处理POST请求时返回303重定向响应。浏览器在网络面板中能看到303响应,也会向重定向URL发起GET请求,但页面并没有跳转到目标地址,仍然停留在发起POST请求的原页面。
详情
1. POST端点Lambda代码
def lambda_handler(event, context): DOMAIN = 'https://<my_Api_gateway_address' response = { "headers": {"Location": DOMAIN+'/success', }, "statusCode": 303, } return response
2. API Gateway的Lambda集成配置

3. 发起初始POST请求的JavaScript代码
var url = "https://<my_Api_gateway_endpoint>"; var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { // Handle the response here if needed console.log(xhr.responseText); } }; xhr.send(formData);
我需要如何操作才能让POST请求后页面实际跳转到重定向地址?
更新内容
1. 更新后的客户端JavaScript代码
var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); xhr.onreadystatechange = function() { console.log(xhr.responseText); console.log(xhr.status); if (xhr.readyState === 4 && xhr.status === 200) { console.log(xhr.responseText); console.log("DONE"); } }; xhr.send(formData);
2. 浏览器控制台日志截图

内容的提问来源于stack exchange,提问作者Kraken
相关产品推荐
相关产品推荐

