Steam Post Request - 无法加载资源:服务器响应状态为400(错误请求)

时间:2014-08-31 22:45:52

标签: 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's robot.txt个文件:

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

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

1 个答案:

答案 0 :(得分:0)

您使用过setRequestHeader吗?

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