简体   繁体   English

使用NEST elasticsearch和C#的授权承载令牌

[英]Authorization bearer token with NEST elasticsearch and C#

I've got a problem while trying to connect to an elasticsearch API. 尝试连接到Elasticsearch API时遇到问题。 The API expect an bearer token, but the NEST lybrary only provides a basic authentication and I've got to pass a custom header as well. 该API需要一个承载令牌,但NEST库仅提供基本身份验证,我还必须传递一个自定义标头。 So, did anybody have to face this problem?? 那么,有人要面对这个问题吗? How to pass custom headers?! 如何传递自定义标题?

Thanks 谢谢

在此处输入图片说明

You can add headers that should be added to all requests on ConnectionSettings 您可以添加应添加到ConnectionSettings所有请求的标头

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
    .GlobalHeaders(new NameValueCollection 
    { 
        { "Authorization", "Bearer fnoi3nfion3fn00jr0j1r0" } 
    });

var client = new ElasticClient(connectionSettings);

您可以在请求中添加任何标头:

req.Headers.Add("CustomeKey", CustomeData);

Actually I was getting a mistaken concept. 其实我得到了一个错误的概念。 Actually I'm interacting with an API wich encapsolate the elasticsearch and just use the elasticsearch query sintax, so I didn't need to use NEST, the elasticsear package, to connect with it. 实际上,我正在与一个将Elasticsearch封装起来的API进行交互,而仅使用elasticsearch查询sintax,因此我不需要使用NEST(即elasticsear软件包)与其进行连接。 And I just got to interact it with a simple http call. 我只需要通过一个简单的http调用进行交互。

Anyway, thanks Russ 无论如何,谢谢拉斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM