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

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

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

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 上的服务器日志时,我收到三行内容:“已收到 get”。

感谢所有帮助,谢谢!

最佳答案

通过以下命令可以看到,对您网站的请求正在使用 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>

关于javascript - 从 Chrome 扩展程序到 App Engine 的 POST 请求作为 GET 请求收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25417915/

相关文章:

javascript - Unity Raycast2D 仅拍摄 1 个单元

java - 生命周期配置 AppEngine 未涵盖的插件执行

google-app-engine - 在服务器端处理带有 "io.Pipe"的大文件上传

java - 对象化/AppEngine/Java : Many-many relationship

php - 如何使用 https-post 将 node.js 的 POST 请求发送到 php 页面?

javascript - 文件输入 : Compare file type and accept only picture formats (jpg, bmp 等)

javascript - 为什么要使用 if (!!err)?

javascript - 无法显示之后添加的元素

java - 如何在 Jersey 使用二进制数据?

java - 对于 Wildfly 中以 .html 文件结尾的 URL,此 URL 不支持 HTTP 方法 POST