Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting Multiple Headers with Flurl

Tags:

c#

flurl

Hi I'm using Flurl and I need to set multiple headers for the post and the documentation on the site states to do await url.WithHeaders(new { h1 = "foo", h2 = "bar" }).GetJsonAsync();

I'm not sure what this means, what is H1, H2 ?

I'm trying to set Headers "API-VERSION:21" and "Authorization: askjdalksdjlaksjdlaksjd";

like image 381
user1012500 Avatar asked Mar 06 '16 11:03

user1012500


1 Answers

Use documentation (a very beautiful one): https://flurl.dev/docs/fluent-http/

// one: 
await url.WithHeader("someheader", "foo").GetJsonAsync();

// multiple: 
await url.WithHeaders(new { h1 = "foo", h2 = "bar" }).GetJsonAsync();

h1 and h2 are names of headers, and "foo" and "bar" are values. As you can see you may also use call .WithHeader("headerName", "headerValue") in your case:

.WithHeader("API-VERSION", "21")
.WithHeader("Authorization", "askjdalksdjlaksjdlaksjd")

In other words chain calls to send multiple headers.

like image 52
csharpfolk Avatar answered Nov 16 '22 09:11

csharpfolk