【发布时间】:2014-10-25 03:48:29
【问题描述】:
我正在尝试发送这样的帖子请求:
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'srobot.txt文件:
User-agent: *
Disallow: /actions/
Disallow: /linkfilter/
Host: steamcommunity.com
上面写着Disallow: /actions/,这就是我收到400 错误的原因吗?
【问题讨论】:
-
你确定在第一个重写规则中它应该是
^api/$而不是^steamapi/$?你确定你已经加载了 mod_proxy 吗? -
steamapi 是我的本地主机服务器上的站点名称
标签: javascript apache .htaccess post steam