Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services VPC HTTP代理缺少AWS API网关响应头_Amazon Web Services_Aws Api Gateway - Fatal编程技术网

Amazon web services VPC HTTP代理缺少AWS API网关响应头

Amazon web services VPC HTTP代理缺少AWS API网关响应头,amazon-web-services,aws-api-gateway,Amazon Web Services,Aws Api Gateway,我正致力于创建一个AWS API网关,该网关具有VPC集成,可以代理另一个内部服务。这是一个POST请求。代理服务在UI中按预期响应,该UI直接调用服务,并附加正确的头 有趣的是,当我使用AWS Amplify调用该服务时,飞行前检查和POST都是成功的,响应体看起来很完美。但我从Amplify(通过axios库)得到了一个通用的“网络错误”。Chrome将此错误记录到控制台:加载失败https://my-amazon-api-url/thing: 请求的资源上不存在“Access Contro

我正致力于创建一个AWS API网关,该网关具有VPC集成,可以代理另一个内部服务。这是一个POST请求。代理服务在UI中按预期响应,该UI直接调用服务,并附加正确的头

有趣的是,当我使用AWS Amplify调用该服务时,飞行前检查和POST都是成功的,响应体看起来很完美。但我从Amplify(通过axios库)得到了一个通用的“网络错误”。Chrome将此错误记录到控制台:
加载失败https://my-amazon-api-url/thing: 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:8080因此,不允许访问。
我不确定为什么这个标题没有出现在回复中,我似乎也找不到一个方法让它出现在回复中。注意:代理服务返回带有响应主体的201。我想这可能与此有关,但我不确定

飞行前标题

响应标题:

accept-encoding: gzip, deflate, br
access-control-allow-credentials: true
access-control-allow-headers: Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Access-Control-Allow-Origin
access-control-allow-methods: POST,OPTIONS
access-control-allow-origin: *
access-control-expose-headers: Access-Control-Allow-Origin
content-length: 0
content-type: application/json
date: Wed, 20 Jun 2018 17:30:10 GMT
status: 200
x-amz-apigw-id: someId
x-amzn-requestid: someID
content-encoding: gzip
content-length: 463
content-type: application/json; charset=utf-8
date: Wed, 20 Jun 2018 17:30:10 GMT
status: 201
x-amz-apigw-id: agatewayId
x-amzn-remapped-connection: keep-alive
x-amzn-remapped-content-length: 866
x-amzn-remapped-date: Wed, 20 Jun 2018 17:30:10 GMT
x-amzn-requestid: aLongId
文章标题

请求标头:

:authority: someAmazonUrl
:method: POST
:path: /thing
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
access-control-allow-origin: *
authorization: AWS4-HMAC-SHA256 Credential=someCredentials, SignedHeaders=access-control-allow-origin;content-type;host;x-amz-date;x-amz-security-token, Signature=aSignature
cache-control: no-cache
content-length: 559
content-type: application/json
dnt: 1
origin: http://localhost:8080
pragma: no-cache
referer: http://localhost:8080/
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
x-amz-date: 20180620T173010Z
x-amz-security-token: aReallyLongToken
响应头:

accept-encoding: gzip, deflate, br
access-control-allow-credentials: true
access-control-allow-headers: Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Access-Control-Allow-Origin
access-control-allow-methods: POST,OPTIONS
access-control-allow-origin: *
access-control-expose-headers: Access-Control-Allow-Origin
content-length: 0
content-type: application/json
date: Wed, 20 Jun 2018 17:30:10 GMT
status: 200
x-amz-apigw-id: someId
x-amzn-requestid: someID
content-encoding: gzip
content-length: 463
content-type: application/json; charset=utf-8
date: Wed, 20 Jun 2018 17:30:10 GMT
status: 201
x-amz-apigw-id: agatewayId
x-amzn-remapped-connection: keep-alive
x-amzn-remapped-content-length: 866
x-amzn-remapped-date: Wed, 20 Jun 2018 17:30:10 GMT
x-amzn-requestid: aLongId
特定路线的招摇过市JSON

"/thing": {
      "post": {
        "operationId": "PostThing",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "Access-Control-Allow-Origin",
            "in": "header",
            "required": false,
            "type": "string"
          },
          {
            "name": "Content-Type",
            "in": "header",
            "required": false,
            "type": "string"
          },
          {
            "name": "Accept-Encoding",
            "in": "header",
            "required": false,
            "type": "string"
          },
          {
            "in": "body",
            "name": "ThingPostBody",
            "required": true,
            "schema": {
              "$ref": "#/definitions/ThingPostBody"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "Access-Control-Allow-Origin": {
                "type": "string"
              }
            }
          },
          "201": {
            "description": "201 response",
            "headers": {
              "Access-Control-Allow-Origin": {
                "type": "string"
              },
              "Content-Encoding": {
                "type": "string"
              },
              "Accept-Encoding": {
                "type": "string"
              },
              "Content-Type": {
                "type": "string"
              }
            }
          },
          "400": {
            "description": "400 response",
            "headers": {
              "Access-Control-Allow-Origin": {
                "type": "string"
              }
            }
          },
          "401": {
            "description": "401 response",
            "headers": {
              "Access-Control-Allow-Origin": {
                "type": "string"
              }
            }
          },
          "403": {
            "description": "403 response",
            "headers": {
              "Access-Control-Allow-Origin": {
                "type": "string"
              }
            }
          }
        },
        "x-amazon-apigateway-integration": {
          "uri": "http://internal-amazon-url/thing",
          "responses": {
            "default": {
              "statusCode": "201",
              "responseParameters": {
                "method.response.header.Access-Control-Allow-Origin": "'*'"
              }
            }
          },
          "requestParameters": {
            "integration.request.header.Access-Control-Allow-Origin": "'*'"
          },
          "passthroughBehavior": "when_no_match",
          "connectionType": "VPC_LINK",
          "connectionId": "someID",
          "httpMethod": "POST",
          "type": "http_proxy"
        }
      },
      "options": {
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "Access-Control-Expose-Headers": {
                "type": "string"
              },
              "Access-Control-Allow-Origin": {
                "type": "string"
              },
              "Access-Control-Allow-Methods": {
                "type": "string"
              },
              "Accept-Encoding": {
                "type": "string"
              },
              "Access-Control-Allow-Headers": {
                "type": "string"
              },
              "Content-Type": {
                "type": "string"
              }
            }
          }
        },
        "x-amazon-apigateway-integration": {
          "responses": {
            "2\\d{2}": {
              "statusCode": "200",
              "responseParameters": {
                "method.response.header.Access-Control-Expose-Headers": "'Access-Control-Allow-Origin,Content-Type,Content-Encoding'",
                "method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",
                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Access-Control-Allow-Origin'",
                "method.response.header.Access-Control-Allow-Origin": "'*'",
                "method.response.header.Accept-Encoding": "'gzip, deflate, br'"
              }
            }
          },
          "requestTemplates": {
            "application/json": "{\"statusCode\": 200}"
          },
          "passthroughBehavior": "when_no_templates",
          "type": "mock"
        }
      }
    }

您的服务使用什么技术?这有什么关系?HTTP是所有服务器都必须遵循的协议,无论实现如何。我曾经遇到过类似的问题,我使用的express应用程序本身需要cors配置,真有趣。我也在使用express.Try
constcors=require(“cors”)。。。app.use(cors())