【发布时间】:2017-09-21 09:01:57
【问题描述】:
我知道在 stackoverflow 上有类似的 Q/A,但我需要 .net 解决方案.....我快疯了...... 我有一个使用 .net C# 返回输入值的简单 lambda
public string FunctionHandler(Input input, ILambdaContext context)
{
return JsonConvert.SerializeObject(input.Name);
}
这个由 API Gateway 触发的 lambda 触发器,也完成了从 aws 在线文档完成的所有步骤!包括启用 CORS 并重新部署 API!仍然报错
请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:7076' 不允许访问。响应的 HTTP 状态代码为 400。
在类似的 Q/A @sqren 中说
如果您启用了 lambda-proxy,则需要手动设置 CORS 标头:
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);
};
请问有没有人有 .net 解决方案来帮我解决这个问题....
任何帮助都非常感谢,我希望 AWS 团队也在关注......即使我创建了 AWS 开发人员支持 QQ......
【问题讨论】:
-
The response had HTTP status code 400.您遇到了错误。400是Bad Request。在这种情况下,您不会期望 CORS 响应。首先要排查问题的是为什么您会收到 400 响应。 -
但是我使用了 postman api 响应状态 200......
-
看起来您正在 jquery 中的应用程序执行 POST 操作,但未配置为发出跨域请求。调用应用程序需要允许跨域请求。你能发布试图调用你的 API 网关的代码吗
标签: c# amazon-web-services lambda