Power BI中的Post方法

时间:2018-05-22 09:26:54

标签: powerbi powerquery powerbi-desktop

我写了Power查询以发布如下方法

  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状态。什么是我的PQL代码中的主要错误?

1 个答案:

答案 0 :(得分:1)

你应该通过&符号而不是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, make http POST request with form data