javascript - Steam 发布请求 - 无法加载资源 : the server responded with a status of 400 (Bad Request)

标签 javascript apache .htaccess post steam

我正在尝试发送这样的帖子请求:

xhr.open("POST", "/steamapi/actions/RemoveFriendAjax", false);
    var params = "sessionID="+session_id+"&steamid="+id;
    xhr.onreadystatechange = function() {//Call a function when the state changes.
        if(xhr.readyState == 4 && xhr.status == 200) {
            alert(xhr.responseText);
        }
    }   
xhr.send(params);

我正在使用 Apache 服务器,这是我的 .htaccess 文件

RewriteEngine On
RewriteRule ^api/(.*)$ http://api.steampowered.com/$1 [P]
RewriteRule ^(.*)$ http://steamcommunity.com/$1 [P]
 <IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
 </IfModule>

每当我发送请求时,我都会收到此错误:

Failed to load resource: the server responded with a status of 400 (Bad Request) 
enter code here

为什么会这样?我在 Steam 上使用了 GET 请求,它们工作正常,但这个 POST 请求似乎不起作用。

编辑:这是 steamcommunity.com 的 robot.txt 文件:

User-agent: *
Disallow: /actions/
Disallow: /linkfilter/
Host: steamcommunity.com

它说 Disallow:/actions/,这就是我收到 400 错误的原因吗?

最佳答案

您是否使用了setRequestHeader

xhr.open("POST", "/steamapi/actions/RemoveFriendAjax", false);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

关于javascript - Steam 发布请求 - 无法加载资源 : the server responded with a status of 400 (Bad Request),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25596961/

相关文章:

python - Apache + Python 瓶 : visitor IP always refers to 127. 0.0.1

javascript - 调试 NodeJS 子进程的 VSCode babel-node

javascript - 从嵌入的 Plunker/StackBlitz 等代码编辑器发送和获取数据

javascript - 为什么我的图像不会出现在 Canvas 上?

java - Websockets 无法在 Google Compute Engine 上部署的 Tomcat 服务器上运行

php - 如何在运行 CLI 和 Apache2Handler 时将系统环境变量导入 PHP?

.htaccess - 对于使用 .htaccess 输入的任何 URL,强制 SSL 到 www 子域?

javascript - 用取消标记或按钮包裹的电子邮件地址

linux - 关闭对文件夹的访问,但打开对文件的访问

php - 重定向后无法访问帖子或从 php 页面获取