<i id='KTNTd'><tr id='KTNTd'><dt id='KTNTd'><q id='KTNTd'><span id='KTNTd'><b id='KTNTd'><form id='KTNTd'><ins id='KTNTd'></ins><ul id='KTNTd'></ul><sub id='KTNTd'></sub></form><legend id='KTNTd'></legend><bdo id='KTNTd'><pre id='KTNTd'><center id='KTNTd'></center></pre></bdo></b><th id='KTNTd'></th></span></q></dt></tr></i><div id='KTNTd'><tfoot id='KTNTd'></tfoot><dl id='KTNTd'><fieldset id='KTNTd'></fieldset></dl></div>

<small id='KTNTd'></small><noframes id='KTNTd'>

    1. <tfoot id='KTNTd'></tfoot>

        • <bdo id='KTNTd'></bdo><ul id='KTNTd'></ul>

        <legend id='KTNTd'><style id='KTNTd'><dir id='KTNTd'><q id='KTNTd'></q></dir></style></legend>

        API Gateway CORS:没有“Access-Control-Allow-Origin"标头

        时间:2023-09-03

            <bdo id='7DvkI'></bdo><ul id='7DvkI'></ul>

              <small id='7DvkI'></small><noframes id='7DvkI'>

              • <i id='7DvkI'><tr id='7DvkI'><dt id='7DvkI'><q id='7DvkI'><span id='7DvkI'><b id='7DvkI'><form id='7DvkI'><ins id='7DvkI'></ins><ul id='7DvkI'></ul><sub id='7DvkI'></sub></form><legend id='7DvkI'></legend><bdo id='7DvkI'><pre id='7DvkI'><center id='7DvkI'></center></pre></bdo></b><th id='7DvkI'></th></span></q></dt></tr></i><div id='7DvkI'><tfoot id='7DvkI'></tfoot><dl id='7DvkI'><fieldset id='7DvkI'></fieldset></dl></div>
                <legend id='7DvkI'><style id='7DvkI'><dir id='7DvkI'><q id='7DvkI'></q></dir></style></legend><tfoot id='7DvkI'></tfoot>
                    <tbody id='7DvkI'></tbody>
                • 本文介绍了API Gateway CORS:没有“Access-Control-Allow-Origin"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  虽然已经通过 API Gateway 设置了 CORS 并且设置了 Access-Control-Allow-Origin 标头,但在 Chrome 中尝试从 AJAX 调用 API 时仍然收到以下错误:

                  <块引用>

                  XMLHttpRequest 无法加载

                  并且来自 OPTIONS 响应:

                  如何在不恢复为 JSON-P 的情况下从浏览器调用我的 API?

                  解决方案

                  我遇到了同样的问题.我已经用了 10 个小时来找出答案.

                  https://serverless.com/framework/docs/providers/aws/events/apigateway/

                  //handler.js'使用严格';module.exports.hello = 函数(事件、上下文、回调){常量响应 = {状态码:200,标题:{"Access-Control-Allow-Origin" : "*",//需要 CORS 支持才能工作"Access-Control-Allow-Credentials" : true//cookie 需要,HTTPS 授权标头},正文: JSON.stringify({ "message": "Hello World!" })};回调(空,响应);};

                  Although CORS has been set up through API Gateway and the Access-Control-Allow-Origin header is set, I still receive the following error when attempting to call the API from AJAX within Chrome:

                  XMLHttpRequest cannot load http://XXXXX.execute-api.us-west-2.amazonaws.com/beta/YYYYY. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.

                  I attempted to GET the URL through Postman and it shows the above header is successfully passed:

                  And from the OPTIONS reponse:

                  How can I call my API from the browser without reverting to JSON-P?

                  解决方案

                  I get the same problem. I have used 10hrs to findout.

                  https://serverless.com/framework/docs/providers/aws/events/apigateway/

                  // handler.js
                  
                  'use strict';
                  
                  module.exports.hello = function(event, context, callback) {
                  
                  const response = {
                    statusCode: 200,
                    headers: {
                      "Access-Control-Allow-Origin" : "*", // Required for CORS support to work
                      "Access-Control-Allow-Credentials" : true // Required for cookies, authorization headers with HTTPS 
                    },
                    body: JSON.stringify({ "message": "Hello World!" })
                  };
                  
                  callback(null, response);
                  };
                  

                  这篇关于API Gateway CORS:没有“Access-Control-Allow-Origin"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:尽管有标头,Firefox '跨源请求被阻止' 下一篇:是否可以捕获 CORS 错误?

                  相关文章

                  最新文章

                    1. <legend id='FvTab'><style id='FvTab'><dir id='FvTab'><q id='FvTab'></q></dir></style></legend>
                    2. <small id='FvTab'></small><noframes id='FvTab'>

                      <tfoot id='FvTab'></tfoot>
                        <bdo id='FvTab'></bdo><ul id='FvTab'></ul>
                      <i id='FvTab'><tr id='FvTab'><dt id='FvTab'><q id='FvTab'><span id='FvTab'><b id='FvTab'><form id='FvTab'><ins id='FvTab'></ins><ul id='FvTab'></ul><sub id='FvTab'></sub></form><legend id='FvTab'></legend><bdo id='FvTab'><pre id='FvTab'><center id='FvTab'></center></pre></bdo></b><th id='FvTab'></th></span></q></dt></tr></i><div id='FvTab'><tfoot id='FvTab'></tfoot><dl id='FvTab'><fieldset id='FvTab'></fieldset></dl></div>