Site
Site

Reputation: 265

POST request from Chrome Extension to App Engine received as GET request

I am trying to send a minimal POST request from a Chrome Extension to a server hosted using Google App Engine. Here is my server code:

class Receive(webapp2.RequestHandler):
    def get(self):
        logging.info('received a get')

    def post(self):
        logging.info('received a post')

Here is the Javascript code in my Chrome Extension:

$.post("http://perativ.com/receive");

$.ajax({
    type: "POST",
    dataType: "JSON",
    url: "http://perativ.com/receive"
});

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://perativ.com/receive");
xhr.send();

I have the <all_urls> permission in my manifest.json file.

I included the three identical requests to show that nothing is working. When I run this Chrome Extension and then check the server logs at perativ.com, I get three lines that say: "received a get".

All help is appreciated, thank you!

Upvotes: 0

Views: 622

Answers (1)

Rob W
Rob W

Reputation: 349012

As you can see by the following command, the request to your website is being redirected from perativ.com to www.perativ.com using HTTP status code 301. When this redirect happens, POST is converted to GET.

To solve the issue, send the request to www.perativ.com instead of perativ.com, OR disable the redirect if it is within your reach.

$ curl -X POST http://perativ.com/receive -H 'Content-Length: 0'
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.perativ.com/receive">here</A>.
</BODY></HTML>

Upvotes: 3

Related Questions