Amazon S3 - 405 方法不允许使用 POST(虽然我允许在存储桶上进行 POST) [英] Amazon S3 - 405 Method Not allowed using POST (Although I allowed POST on the bucket)

查看:52
本文介绍了Amazon S3 - 405 方法不允许使用 POST(虽然我允许在存储桶上进行 POST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing a problem that my graph (Using AJAX - POST - PHP) is not appearing on Amazon

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

它说(错误的方法 405 错误)

its says (Wrong Method 405 Error)

这是我的 CORS 配置:

This is my CORS Config :

<?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)上运行良好

Its working fine on localhost (WAMPServer)

你能帮我吗?

推荐答案

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

The direct cause of the error is unrelated to CORS, and is actually caused by the fact that that the S3 website endpoints don't support POST (only the REST endpoints support it, but that's not actually related to the problem at hand).

真正的问题是您似乎试图将 S3 用于它不做的事情.

The real problem is that you appear to be trying to use S3 for something it doesn't do.

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

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

S3 is an object store, not an application server.

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

You can't run php on S3. You can't execute any server-side code on S3.

您可以在 Amazon S3 上托管静态网站.在静态网站上,单个网页包含静态内容.它们还可能包含客户端脚本.相比之下,动态网站依赖于服务器端处理,包括服务器端脚本,如 PHP、JSP 或 ASP.NET.Amazon 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/最新/开发/WebsiteHosting.html

文档的同一页将为您指明替代 AWS 解决方案,以完成您想要的工作.

That same page of the documentation will point you to alternative AWS solutions for accomplishing what you want.

这篇关于Amazon S3 - 405 方法不允许使用 POST(虽然我允许在存储桶上进行 POST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆