从Chrome扩展程序到App Engine的POST请求作为GET请求收到

时间:2014-08-21 03:45:57

标签: javascript google-app-engine post google-chrome-extension get

我正在尝试将Chrome扩展程序中的最小POST请求发送到使用Google App Engine托管的服务器。这是我的服务器代码:

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

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

以下是Chrome扩展程序中的Javascript代码:

$.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();

我的<all_urls>文件中有manifest.json权限。

我列出了三个相同的请求,表明没有任何工作。当我运行这个Chrome扩展程序,然后检查perativ.com上的服务器日志时,我得到三行说“收到了一个”。

感谢所有帮助,谢谢!

1 个答案:

答案 0 :(得分:3)

正如您可以通过以下命令看到的,使用HTTP状态代码301将对您网站的请求从perativ.com重定向到www.perativ.com。当此重定向发生时,POST将转换为GET。

要解决此问题,请将请求发送至www.perativ.com而非perativ.com,或者如果触手可及,请停用重定向。

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