【发布时间】:2015-06-19 23:31:20
【问题描述】:
我正在使用 C# 编写一个 .net 应用程序,以编程方式在 fiware 上针对 hdfs 运行 REST api,但在 http POST 操作上它失败并显示 401(拒绝访问)。它适用于简单的 GET 操作,但我不确定如何进行身份验证。从规范看来,SPEGNA 和委派的身份验证令牌是两个选项,但我如何以编程方式执行此操作?我只有我的用户名和密码可以关闭。我正在使用 RestSharp 库来简化休息交互。
此代码有效
var client = new RestClient("http://cosmos.lab.fi-ware.org:14000");
request = new RestRequest("webhdfs/v1/user/<userID>");
request.AddParameter("op", "LISTSTATUS");
request.AddParameter("user.name", "<userID>");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
此代码因 http 401 而失败
var client = new RestClient("http://cosmos.lab.fi-ware.org:14000");
var request = new RestRequest("webhdfs/v1/user/<userID>/structured_data123.txt",Method.PUT);
request.AddParameter("op", "CREATE");
request.AddParameter("user.name", "<userID>");
IRestResponse response = client.Execute(request);
HTTP 状态 401 - org.apache.hadoop.security.authentication.client.AuthenticationException:不允许匿名请求
想法?想法?提前谢谢你!
【问题讨论】: