2 years ago

#77050

test-img

Alex_P

How to assign Headers to HttpRequestMessage?

I wanted to assign the headers first like this:

> requestMsg.Headers <- seq { "x-rapidapi-host", "yh-finance.p.rapidapi.com"; "x-rapidapi-key", "3a9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5f0" };;

But it throws the error:

stdin(8,1): error FS0810: Property 'Headers' cannot be set

Then I saw the option to assign properties with object initialization in this SO question: Object Initilization syntax. Based on that I wanted to assign the Header.

let request = new HttpRequestMessage(
  Headers = seq { "x-rapidapi-host", "yh-finance.p.rapidapi.com"; 
                  "x-rapidapi-key", "3a9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5f0" });;

But it throws this error:

let request = new HttpRequestMessage(Headers = seq { "x-rapidapi-host", "yh-finance.p.rapidapi.com"; "x-rapidapi-key", "3a9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5f0" });;
  --------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(14,15): error FS0508: No accessible member or object constructor named 'HttpRequestMessage' takes 0 arguments. The named argument 'Headers' doesn't correspond to any argument or settable return property for any overload.

How can I add a header for my HttpRequestMessage?

f#

dotnet-httpclient

0 Answers

Your Answer

Accepted video resources