来自AWS API Gateway的预检响应中的Access-Control-Allow-Methods不允许使用方法PUT

Jus*_*808 8 amazon-web-services swagger aws-lambda aws-api-gateway

我有API网关设置指向lambda函数,设置为aws_proxy.我可以GET,POST,DELETE就好了,但我正在尝试添加一个PUT而且我得到了Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.

XMLHttpRequest无法加载https://api.small.pictures/picture/07e78691-20f9-4a20-8be5-458eaeb73a63.在预检响应中,Access-Control-Allow-Methods不允许使用方法PUT.

我想我的CORS设置正确.这是该路线的招摇用户.

  '/picture/{picId}':
    options:
      summary: CORS support
      description: |
        Enable CORS by returning correct headers
      consumes:
        - application/json
      produces:
        - application/json
      tags:
        - CORS
      x-amazon-apigateway-integration:
        type: mock
        requestTemplates:
          application/json: |
            {
              "statusCode" : 200
            }
        responses:
          "default":
            statusCode: "200"
            responseParameters:
              method.response.header.Access-Control-Allow-Headers : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
              method.response.header.Access-Control-Allow-Methods : "'*'"
              method.response.header.Access-Control-Allow-Origin : "'*'"
            responseTemplates:
              application/json: |
                {}
      parameters:
        - name: picId
          in: path
          required: true
          type: string
      responses:
        200:
          description: Default response for CORS method
          headers:
            Access-Control-Allow-Headers:
              type: "string"
            Access-Control-Allow-Methods:
              type: "string"
            Access-Control-Allow-Origin:
              type: "string"
    x-amazon-apigateway-any-method:
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
      x-swagger-router-controller: main
      x-lambda-function: ../../swiki/build/picture
      x-amazon-apigateway-integration:
        type: aws_proxy
        httpMethod: POST
        uri: arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/@@LambdaFunctionPicture/invocations
        credentials: @@APIGatewayExecutionRole
Run Code Online (Sandbox Code Playgroud)

正如你可以看到我有Access-Control-Allow-Headers,Access-Control-Allow-MethodsAccess-Control-Allow-Origin配置.

为什么我不能提出PUT请求?

jen*_*ter 14

目前,大多数浏览器似乎都不支持在允许的方法上设置'*'.因此,您必须手动设置方法以实现浏览器支持.

Access-Control-Allow-Methods: POST, PUT, GET, OPTIONS
Run Code Online (Sandbox Code Playgroud)

访问控制允许的方法

兼容性说明

最新规范中提到的通配符值(*)尚未在浏览器中实现:

铬:问题615313

Firefox:错误1309358

伺服:问题13283