【问题标题】:Fsharp.Data HttpRequestBody getting 'The mandatory 'grant_type' parameter is missing'Fsharp.Data HttpRequestBody 得到“缺少强制的 'grant_type' 参数”
【发布时间】:2021-04-19 15:29:35
【问题描述】:

我正在对男性 HttpRequests 使用 Fsharp.Data。 我想从 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 中使用了相同的参数,它在哪里起作用。

有什么想法吗? 谢谢

【问题讨论】:

  • 如果您将内容类型更改为 HttpContentTypes.Json,因为您在正文中传递 Json,会发生什么情况?
  • @JasonDown:然后我得到'Content-Type' header is not valid.
  • 你在下面看到我的回答了吗?您不应该将正文作为 JSON 发送。
  • 是的,但在它起作用之前,我一直在努力使用正确的语法。感谢您的帮助!

标签: f# httprequest f#-data


【解决方案1】:

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

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

不过,我还没有测试过。

【讨论】:

  • 谢谢。让我朝着正确的方向前进。 body = FormValues ["grant_type", "password"; "password","xxxxx; "username", "y@.....] 是解决方案。我是 F# 初学者,所以 seq 格式是我最大的挑战......
  • 如果您将每个条目放在单独的行上,您可以省略分号。
猜你喜欢
  • 2019-05-16
  • 2012-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-14
  • 2021-01-04
  • 2019-12-11
  • 1970-01-01
相关资源
最近更新 更多