I am using F# library HttpFs.Client for API Testing. I know that I am doing something wrong by not setting the correct content type in Headers but I don't know how to set it.
[]
let Play with Rest API() =
let request = Request.createUrl Post "https://c2c-lms-qa.ninja24.in/login"
|> Request.setHeader (Accept "application/json")
|> Request.bodyString ReadFile //Reading content of json body
|> Request.responseAsString
|> run
printfn "Here's the Response is : %s" request
In this case, I keep getting an error: {"code":"415","message":"Content type '' not supported","errors":[{"field":null,"message":"Content type '' not supported","rejectedValue":null}]}Here's the Response is : {"code":"415","message":"Content type '' not supported","errors":[{"field":null,"message":"Content type '' not supported","rejectedValue":null}]}
I tried various other ways like bypassing these: a) |> Request.setHeader (ContentType "application/json")
Showing an error: This expression was expected to have type 'ContentType' but here has type 'string' Or
b) |> Request.setHeader (Custom("Content-Type", "application/json"))
System.Exception : Exception raised by job ----> System.InvalidOperationException : Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.Result message:
JSON body: { "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCINCwiZXhwIwQHWsiA8A-mm9jZ33VM3BGeBW9CsJmaeZ4P4uTTQ13PKEboXLu7Heik4UNUfyL1xHvjVVPuIiz--gzzXGN76-ReJ5jHoG_l0JauKbJpgap-HE43JqF08c7zBuHFUp9DmjyNlcbZra7TJsMKPVE7oCYPSpbhCRYLyzlms5xBFO5aqL-IPEOnXJbLkXA", "type": "GOOGLE_LOGIN" }
Note* As suggested, I have tried by removing content-type param itself like:
let Play with Rest API() =
printfn "Body File content is : %s" ReadFile
let request = Request.createUrl Post "https://c2c-lms-qa.ninja24.in/login”
|> Request.bodyString ReadFile
|> Request.responseAsString
|> run
printfn "Here's the Response is : %s" request
But I am still getting this error: Here's the Response is : {"code":"415","message":"Content type '' not supported","errors":[{"field":null,"message":"Content type '' not supported","rejectedValue":null}]}
To Repro on postman, you can use this data: POST URl: https://c2c-lms-qa.ninja24.in/login Body: {"idToken":"eyJhbGciOiJSUzI1NiKNMULubJGpLSGP4Rjsibf9sQGIFy3cnb46wsn0-L03vNu9LuZidwZ30ZiZ28Jua3jQha__yjmdnqaBrkdSybjz1jOsQ4IwQHWsiA8A-mm9jZ33VM3BGeBW9CsJmaeZ4P4uTTQ13PKEboXLu7Heik4UNUfyL1xHvjVVPuIiz--gzzXGN76-ReJ5jHoG_l0JauKbJpgap-HE43JqF08c7zBuHFUp9DmjyNlcbZra7TJsMKPVE7oCYPSpbhCRYLyzlms5xBFO5aqL-IPEOnXJbLkXA","type":"GOOGLE_LOGIN"}
As I have provided invalid token, you'll see this expected response in Postman: { "code": "401", "message": "Invalid Token", "errors": [ { "field": null, "message": "Invalid Token", "rejectedValue": null } ] }
But on F# library HttpFs.Client, I get this: {"code":"415","message":"Content type '' not supported","errors":[{"field":null,"message":"Content type '' not supported","rejectedValue":null}]}