【问题标题】:Steam Post Request - Failed to load resource: the server responded with a status of 400 (Bad Request)Steam 发布请求 - 加载资源失败:服务器响应状态为 400(错误请求)
【发布时间】: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


【解决方案1】:

你用过setRequestHeader吗?

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

【讨论】:

  • 设置一个jsFiddle并在这里发帖。
  • 我该如何设置?
  • 这只是一个站点jsfiddle.net,您可以在其中创建一个公开的工作页面,供人们查看并尝试调试问题。
  • 或者,如果您已经有一个公共服务器托管有问题的网站,只需在此处发布链接。
  • 这是 jsfiddle:它没有引用 javascript 方法,我不知道为什么。 jsfiddle.net/Varun_5/t5guw1c7/3
猜你喜欢
  • 2022-06-15
  • 2020-09-21
  • 1970-01-01
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-12
相关资源
最近更新 更多