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);
  });
}

相关内容

热门资讯

透视指南!红龙poker辅助(... 透视指南!红龙poker辅助(HHpoker模拟器)竟然存在有辅助神器(哔哩哔哩)1、下载好红龙po...
透视经验!hhpoker有没有... 透视经验!hhpoker有没有外开挂(WePoKer辅助挂)总是真的有辅助教程(哔哩哔哩)1、hhp...
透视诀窍!wpk俱乐部是真的吗... 透视诀窍!wpk俱乐部是真的吗(WPK安装)一贯是有辅助方法(哔哩哔哩)1、上手简单,内置详细流程视...
透视练习!hhpoker是正规... 透视练习!hhpoker是正规的吗(WePoKer安卓)果然是真的有辅助方法(哔哩哔哩)1、上手简单...
透视大纲!wepoker数据分... 透视大纲!wepoker数据分析工具(HHpoker有辅助)好像真的是有辅助插件(哔哩哔哩)1、每一...
透视手段!德普之星透视辅助插件... 透视手段!德普之星透视辅助插件(WePoKer价格)真是真的有辅助插件(哔哩哔哩)1、完成德普之星透...
透视绝活!fishpoker透... 透视绝活!fishpoker透视底牌(AApoker ai)果然真的有辅助app(哔哩哔哩)1、在f...
透视要领!xpoker辅助怎么... 透视要领!xpoker辅助怎么用(HHpoker有辅助)好像存在有辅助技巧(哔哩哔哩)1、游戏颠覆性...
透视积累!约局吧开挂(WePo... 透视积累!约局吧开挂(WePoKer安装)好像存在有辅助插件(哔哩哔哩)1、游戏颠覆性的策略玩法,独...
透视举措!hhpoker德州作... 透视举措!hhpoker德州作必弊(WePoKer价格)确实真的有辅助脚本(哔哩哔哩)1、hhpok...