10

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";

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
user1012500
  • 1,547
  • 1
  • 16
  • 31

2 Answers2

21

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.

Todd Menier
  • 37,557
  • 17
  • 150
  • 173
csharpfolk
  • 4,124
  • 25
  • 31
0

The suggestion about WithHeaders looks correct. But looking at the code it doesn't look like WithHeader can be chained.

enter image description here

AndersBaumann
  • 407
  • 1
  • 5
  • 11