Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
772 views
in Technique[技术] by (71.8m points)

javascript - Steam Post请求-加载资源失败:服务器响应状态为400(错误请求)(Steam Post Request - Failed to load resource: the server responded with a status of 400 (Bad Request))

I'm trying to send a post request like this:

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

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);

I'm using an Apache Server, and this is my .htaccess file

(我正在使用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>

Whenever I send the request I get this error:

(每当我发送请求时,都会出现此错误:)

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

Why is this happening?

(为什么会这样呢?)

I have used GET requests with Steam and they work fine, put this POST request doesn't seem to be working.

(我已经将GET请求与Steam一起使用,并且它们可以正常工作,但此POST请求似乎不起作用。)

EDIT: This is steamcommunity.com's robot.txt file:

(编辑:这是steamcommunity.com's robot.txt文件:)

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

It says Disallow: /actions/ , so is this the reason why I'm getting a 400 error?

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

  ask by Varun Iyer translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you use setRequestHeader ?

(您使用setRequestHeader吗?)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...