EasyHttp / EasyHttp

Http Library for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you add an Authorization header containing a bearer token?

ezekg opened this issue · comments

For example, how would I make a request like the one below?

HTTP GET https://example.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer d352b45d-0e5b-4c2d-a10b-c7be8c7cd3ff

I would expect to be able to do something like,

using EasyHttp.Http;

var http = new HttpClient();
http.Request.ContentType = "application/json";
http.Request.Accept = "application/json";
http.Request.Authorization = "Bearer d352b45d-0e5b-4c2d-a10b-c7be8c7cd3ff";

var response = http.Get("https://example.com");

But there's no Authorization field exposed, which is odd. Am I missing it somewhere?

commented

Have you tried adding a new header to the request object?

http.Request.Headers.Add("Authorization", "Bearer d352b45d-0e5b-4c2d-a10b-c7be8c7cd3ff");

@ezekg To set the Authorization, you can write something like the following:

http.Request.AddExtraHeader("Authorization", "Bearer d352b45d-0e5b-4c2d-a10b-c7be8c7cd3ff")