You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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集成配置

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 13:24:57