2017-07-04 126 views
0

我已經將API網關設置爲指向lambda函數,設置爲aws_proxy。我可以GET,POST,刪除就好,但我想添加一個PUT,我得到Method PUT is not allowed by Access-Control-Allow-Methods in preflight response方法PUT不允許來自AWS API網關的預檢響應中的訪問控制允許方法

XMLHttpRequest無法加載https://api.small.pictures/picture/07e78691-20f9-4a20-8be5-458eaeb73a63。預檢響應中的訪問控制 - 允許 - 方法不允許方法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 

正如你可以看到我有Access-Control-Allow-HeadersAccess-Control-Allow-MethodsAccess-Control-Allow-Origin配置。

爲什麼我無法發出PUT請求?

回答

4

目前,在允許的方法上設置'*'似乎不被大多數瀏覽器支持。因此,您必須手動明確設置方法以實現瀏覽器支持。

Access-Control-Allow-Methods

兼容性的注意事項

是在 最新的說明書中提到的通配符值(*),是不是在瀏覽器中還沒有實現:

鉻:發行615313

Firefox:bug 1309358

伺服:發行13283

相關問題