Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

php - Amazon S3 - 405 Method Not allowed using POST (Although I allowed POST on the bucket)

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/

its says (Wrong Method 405 Error)

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>

And this is my Script:

<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>

Its working fine on localhost (WAMPServer)

Can you help me please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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 is an object store, not an application server.

You can't run php on S3. You can't execute any server-side code on 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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...