gpt4 book ai didi

php - Amazon S3 - 405 方法不允许使用 POST(尽管我允许在存储桶上使用 POST)

转载 作者:可可西里 更新时间:2023-10-31 22:41:47 25 4
gpt4 key购买 nike

我遇到的问题是我的图表(使用 AJAX - POST - PHP)没有出现在亚马逊上

http://cdpmotest.s3-website.eu-central-1.amazonaws.com/

它说(Wrong Method 405 Error)

这是我的 CORS 配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

这是我的脚本:

<script>
$(document).ready(function(){
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
$.ajax({
url: 'graph-data.php',
type: 'POST',
dataType: 'json',
success: function(data) {
var array1 = data.map(function(item) {
return parseInt(item[1], 10);
});
var array2 = data.map(function(item) {
return parseInt(item[2], 10);
});

createGraph(array1, array2);
}
});//end AJAX request

function createGraph(array1, array2) {
var ctx = document.getElementById("chart-area1").getContext("2d");
var barChartData = {
labels : ["Land Acquisition","Design Concept","Permits and Licensing","Tendering","Elec.+Water Requests","Construction Start","Construction Finish","Site Handover"],
datasets : [
{
fillColor : "rgba(0,154,166,0.5)",
strokeColor : "rgba(0,154,166,0.8)",
highlightFill: "rgba(0,154,166,0.75)",
highlightStroke: "rgba(0,154,166,1)",
data : array1
},
{
fillColor : "rgba(77,79,83,0.5)",
strokeColor : "rgba(77,79,83,0.8)",
highlightFill : "rgba(77,79,83,0.75)",
highlightStroke : "rgba(77,79,83,1)",
data : array2
}
]
}//end bar chart data

window.myBar = new Chart(ctx).Bar(barChartData, {
responsive : true
});
}//end createGraph
});
</script>

它在本地主机(WAMPServer)上运行良好

你能帮帮我吗?

最佳答案

错误的直接原因与CORS无关,实际上是由于S3网站端点不支持POST(只有REST端点支持,但不是)实际上与手头的问题有关)。

真正的问题是您似乎在尝试使用 S3 来做它不做的事情。

 $.ajax({
url: 'graph-data.php',
type: 'POST',

S3 是一个对象存储,而不是应用程序服务器。

你不能在 S3 上运行 php。您不能在 S3 上执行任何服务器端代码。

You can host a static website on Amazon S3. On a static website, individual web pages include static content. They may also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts such as PHP, JSP, or ASP.NET. Amazon S3 does not support server-side scripting.

http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

该文档的同一页将向您指出替代 AWS 解决方案来完成您想要的。

关于php - Amazon S3 - 405 方法不允许使用 POST(尽管我允许在存储桶上使用 POST),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com