【问题标题】:Ambari api POST complaining CSRF protectionAmbari api POST 抱怨 CSRF 保护
【发布时间】:2016-09-12 18:39:45
【问题描述】:

我正在尝试使用以下命令通过 Ambari API 设置 hbase 属性

curl -u "admin:admin" -i -X POST -d '{"type": "hbase-site", "tag": "version3", "properties" : {"hbase.regionserver.global.memstore.size" : "0.6"}}' https://abct.net/api/v1/clusters/xyz/configurations

但不断出现以下错误

HTTP/1.1 400 Bad Request
Content-Length: 107
Content-Type: text/plain
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: Microsoft-IIS/8.5
x-ms-hdi-active: 10.8.18.29
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
User: admin
X-Powered-By: ARR/3.0
Set-Cookie: AMBARISESSIONID=2e8ortl32j1p7zdjatigdgvg;Path=/;HttpOnly; path=/; secure
X-Powered-By: ASP.NET
Date: Mon, 12 Sep 2016 18:19:38 GMT

{
  "status" : 400,
  "message" : "CSRF protection is turned on. X-Requested-By HTTP header is required."
}

这里缺少什么?

【问题讨论】:

  • 答案对你有用吗?

标签: hortonworks-data-platform azure-hdinsight ambari


【解决方案1】:

事实证明,您必须 add the request header 来处理除 GET 请求之外的任何请求。

您可以添加标题

curl --header "X-Requested-By: my_computer_name"

或者

你可以disable this feature

【讨论】:

    【解决方案2】:

    我在 C# Rest 客户端中遇到了同样的问题。使用 Brig 的答案修复它:

            HttpClientHandler handler = new HttpClientHandler
            {
                Credentials = new System.Net.NetworkCredential("xxxx", "yyyyy"),
            };
    
            using (var httpClient = new HttpClient(handler))
            {
                //"X-Requested-By: my_computer_name"
                httpClient.DefaultRequestHeaders.Add("X-Requested-By","my_computer_name");
    

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 1970-01-01
      • 2014-04-13
      • 2019-07-14
      • 2014-02-19
      • 2016-09-05
      • 2017-01-21
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多