0

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?

Alex_P
  • 2,580
  • 3
  • 22
  • 37
  • https://stackoverflow.com/questions/13858166/how-to-add-headers-to-a-httprequestmessage/13858243 – Jim Foye Jan 20 '22 at 21:42
  • 1
    I recommend using the [HTTP utilities from FSharp.Data](https://fsprojects.github.io/FSharp.Data/library/Http.html#Query-parameters-and-headers) instead of the raw .NET HTTP API. – Brian Berns Jan 20 '22 at 23:53

0 Answers0