简体   繁体   English

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

[英]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. 我正在尝试从Chrome扩展程序向使用Google App Engine托管的服务器发送最小的POST请求。 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: 这是我的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();

I have the <all_urls> permission in my manifest.json file. 我的manifest.json文件中具有<all_urls>权限。

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". 当我运行此Chrome扩展程序,然后在perativ.com上检查服务器日志时,我得到三行内容:“ received a get”。

All help is appreciated, thank you! 感谢所有帮助,谢谢!

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. 如下面的命令所示,正在使用HTTP状态代码301将对您网站的请求从perativ.com重定向到www.perativ.com。当发生这种重定向时,POST将转换为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. 要解决此问题,请将请求发送到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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM