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

相关内容

热门资讯

外挂讲义!wepoker透视有... 外挂讲义!wepoker透视有吗,智星德州插件最新版本更新内容详解-都是是真的有辅助工具(哔哩哔哩)...
外挂经验!哈糖大菠萝破解器,w... 外挂经验!哈糖大菠萝破解器,werplan免费挂下载-确实真的是有辅助神器(哔哩哔哩)进入游戏-大厅...
外挂演示!werplan辅助软... 外挂演示!werplan辅助软件,pokemomo辅助工具-果然一直都是有辅助工具(哔哩哔哩)1、外...
外挂项目!hardrock透视... 外挂项目!hardrock透视工具,agpoker辅助-一直一直都是有辅助app(哔哩哔哩)1、让任...
外挂阶段!fishpoker透... 外挂阶段!fishpoker透视底牌,pokerworld破解版下载-其实有辅助神器(哔哩哔哩)po...
外挂窍门!聚星ai辅助工具激活... 外挂窍门!聚星ai辅助工具激活码,佛手在线大菠萝智能辅助器-好像是真的有辅助插件(哔哩哔哩)1、全新...
外挂演示!德扑圈透视,德普之星... 外挂演示!德扑圈透视,德普之星透视辅助软件激活码-都是真的有辅助神器(哔哩哔哩)该软件可以轻松地帮助...
外挂学习!扑克之星辅助,德州透... 外挂学习!扑克之星辅助,德州透视插件-其实一直都是有辅助软件(哔哩哔哩)1、不需要AI权限,帮助你快...
外挂秘籍!智星菠萝透视,约局吧... 外挂秘籍!智星菠萝透视,约局吧德州真的存在透视吗-都是有辅助方法(哔哩哔哩)1、上手简单,内置详细流...
外挂讲义!uupoker透视,... 外挂讲义!uupoker透视,pokermaster辅助器-确实有辅助脚本(哔哩哔哩)1、玩家可以在...