来自AWS API网关的预检响应中Access-Control-Allow-Methods不允许方法PUT [英] Method PUT is not allowed by Access-Control-Allow-Methods in preflight response, from AWS API Gateway
问题描述
我已经将API网关设置为指向lambda函数,设置为aws_proxy
.我可以进行GET,POST,DELETE的操作,但是我试图添加一个PUT并得到Method PUT is not allowed by Access-Control-Allow-Methods in preflight response
.
I've got API Gateway setup to point to a lambda function, setup as a aws_proxy
. I can GET, POST, DELETE just fine, but I'm trying to add a PUT and I getting 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.
XMLHttpRequest cannot load https://api.small.pictures/picture/07e78691-20f9-4a20-8be5-458eaeb73a63. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.
我认为我的CORS设置正确.这是该路线的招摇使用者.
I think I have my CORS setup properly. Here is the swagger user for the route.
'/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-Headers
,Access-Control-Allow-Methods
和Access-Control-Allow-Origin
.
As you can see I have Access-Control-Allow-Headers
, Access-Control-Allow-Methods
and Access-Control-Allow-Origin
configured.
为什么我不能提出PUT请求?
Why can't I make a PUT request?
推荐答案
当前,大多数浏览器似乎不支持在允许的方法上设置"*".因此,必须手动设置显式方法才能获得浏览器支持.
Currently, setting '*' on the allowed methods seems not to be supported by most browsers. So you must set the methods explicitly by hand to achieve browser support.
Access-Control-Allow-Methods: POST, PUT, GET, OPTIONS
兼容性说明
Compatibility notes
最新规范,尚未在浏览器中实现:
The wildcard value (*) that is mentioned in the latest specification, is not yet implemented in browsers:
铬:问题615313
Chromium: Issue 615313
Firefox:错误1309358
Firefox: bug 1309358
伺服:问题13283
Servo: Issue 13283
这篇关于来自AWS API网关的预检响应中Access-Control-Allow-Methods不允许方法PUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!