1

我写了电源查询来发布如下方法

  let
    url = "https://XXXXXXXXXX/OAuth/Token",
    body = "{
              ""grant_type"": ""password"",
              ""client_id"": ""XXXXXXXX"",
              ""client_secret"": ""XXXXXXXXX"",
              ""redirect_uri"": ""https://XXXXXXX/home/"",
              ""username"": ""user"",
              ""password"": ""password""

    }",
   Source  = Json.Document(Web.Contents(url,
   [ 
     Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
     Content=Text.ToBinary(body)
   ]
   )
   ),
    #"Converted to Table" = Record.ToTable(Source)
in
   #"Converted to Table"

但是我收到 400 错误请求错误,例如

DataSource.Error: Web.Contents failed to get contents from 'https://XXXXX/OAuth/Token' (400): Bad Request
Details:
    DataSourceKind=Web
    DataSourcePath=https://XXXXXXX/OAuth/Token
    Url=https://XXXXXXXXXX/OAuth/Token

当我尝试使用邮递员时,我得到 200 Ok status 。我的 PQL 代码中的主要错误是什么?

4

1 回答 1

2

您应该通过&符号而不是 JSON 将正文作为 urlencoded 字符串发送

所以身体应该是这样的

body="grant_type=password&client_id=XXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=https%3A%2F%2FXXXXXXX%2Fhome%2F&username=user&password=password"

看看这个 - Power Query,使用表单数据发出 http POST 请求

于 2018-05-23T18:12:08.187 回答