Fsharp.Data HttpRequestBody 获取“缺少必需的‘grant_type’参数”

问题描述

我正在使用 Fsharp.Data 处理男性 HttpRequest。 我想从 URL 获取我的令牌。 我试过了(从这里SO

let request () =
    async {
      let url = tokenUrl
      return! Http.AsyncRequestString
        ( url,headers = [ ContentType HttpContentTypes.FormValues;
           Origin "https://www....;
           Referer "https://www.../login";
           Accept "application/json,text/plain,*/*"],body = TextRequest """ {"grant_type": "password","password": "xxx","username": "y@..."} """ )
    } |>  Async.Catch

但我明白

'缺少必需的 'grant_type' 参数'

我在 Python 中使用了相同的参数,在那里它起作用了。

有什么想法吗? 谢谢

解决方法

我认为这里的问题是您将正文作为 JSON 发送,当 it should be form values:

body =
    FormValues [
        "grant_type","password"
        "password","xxx"
        "username","y@..."
    ]

不过我还没有测试过。