Angular与API网关,POST请求遭到了跨站资源共享(CORS)的阻止。
创始人
2024-10-30 18:00:42
0
  1. 在API网关上配置跨域策略,允许来自 Angular 应用程序的请求。例如,以下是一个允许所有来源访问的示例:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAllOrigins",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:region:account-id:api-id/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": [
                        "0.0.0.0/0"
                    ]
                }
            }
        }
    ]
}
  1. 在 Angular 应用程序中使用代理配置来跨域。例如,以下是 proxy.conf.json 文件的示例,用于将所有以 /api 开头的请求代理到 API 网关:
{
   "/api/*": {
      "target": "https://api-gateway-endpoint.com",
      "secure": true,
      "changeOrigin": true
   }
}
  1. 在发送 POST 请求时,将要发送的数据转换为 FormData,然后将其作为请求的 body 发送,例如:
postData() {
  const data = new FormData();
  data.append('username', 'johndoe');
  data.append('password', 'secret');

  this.http.post('https://api-gateway-endpoint.com/api/login', data).subscribe(response => {
    console.log(response);
  });
}

相关内容

热门资讯

九分钟辅助!hhpoker作弊... 九分钟辅助!hhpoker作弊实战视频,wpk俱乐部是真的吗,指南教程(有挂猫腻)1、hhpoker...
第九分钟辅助!wepoker软... 第九分钟辅助!wepoker软件安装包,hh poker软件,手册教程(今日头条)一、wepoker...
七分钟辅助!wepoker插件... 七分钟辅助!wepoker插件辅助,约局吧德州真的存在透视吗,大纲教程(有挂猫腻)1、约局吧德州真的...
三分钟辅助!hh poker软... 三分钟辅助!hh poker软件,wepoker线上大神,课程教程(有挂详情)1、在wepoker线...
七分钟辅助!aapoker万能... 七分钟辅助!aapoker万能辅助器,佛手大菠萝有挂吗,策略教程(有挂教程)所有人都在同一条线上,像...
8分钟辅助!wepoker私人... 8分钟辅助!wepoker私人局透视插件,约局吧透视挂下载,窍门教程(有挂方法)1、让任何用户在无需...
第1分钟辅助!we-poker... 第1分钟辅助!we-poker正规吗,xpoker辅助神器,演示教程(有挂辅助)1、下载好xpoke...
两分钟辅助!wepoker有透... 两分钟辅助!wepoker有透视底牌吗,德扑圈透视挂,办法教程(有挂规律)暗藏猫腻,小编详细说明we...
第2分钟辅助!hhpoker真... 第2分钟辅助!hhpoker真的有透视吗,wepoker看底牌,法子教程(有挂猫腻)1、许多玩家不知...
四分钟辅助!hhpoker辅助... 四分钟辅助!hhpoker辅助软件,xpoker透视辅助,要领教程(果真有挂)1、超多福利:超高返利...