简体   繁体   中英

Authorization bearer token with NEST elasticsearch and C#

I've got a problem while trying to connect to an 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. 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

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. And I just got to interact it with a simple http call.

Anyway, thanks Russ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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