1

I'm writing a .net application with C# to programmatically run REST apis against hdfs on fiware but on http POST operations it fails with 401 (access denied). it works for simple GET operations but I'm not sure how to do authentication. From the spec it seems SPEGNA and delegated auth tokens are two options but how do i do this programmatically? I only have my user name and password to go off of. I'm using the RestSharp library to make rest interactions easier.

This code works

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

this code fails with 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 Status 401 - org.apache.hadoop.security.authentication.client.AuthenticationException: Anonymous requests are disallowed

Thoughts? ideas? thank you in advance!

4

1 回答 1

0

在不是 RestSharp 专家的情况下,我已经看到该addParameter方法支持 5 种类型的参数(链接)。

根据这 5 种类型,WebHDFS 请求需要参数类型为“QueryString”(参数必须添加到请求 URI 中,而不是请求正文的一部分);

request.AddParameter("op", "CREATE", ParameterType.QueryString);
request.AddParameter("user.name", "<userID>", ParameterType.QueryString);
于 2015-06-22T06:14:40.727 回答