Steam Post请求-加载资源失败:服务器的响应状态为400(错误请求)

Steam Post Request - Failed to load resource: the server responded with a status of 400 (Bad Request)

本文关键字:请求 状态 响应 错误 服务器 Post 加载 资源 失败 Steam      更新时间:2023-09-26

我正试图发送一个如下的张贴请求:

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's 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");