Post Power BI 中的方法
Post Method in Power BI
我将 Power 查询写入 post 方法,如下所示
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
当我尝试使用 postman 时,我得到 200 Ok 状态。我的 PQL 代码中的主要错误是什么?
您应该将 body 作为由 & 符号连接的 urlencoded 字符串发送,而不是 JSON
所以body应该是这样的
body="grant_type=password&client_id=XXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=https%3A%2F%2FXXXXXXX%2Fhome%2F&username=user&password=password"
我将 Power 查询写入 post 方法,如下所示
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
当我尝试使用 postman 时,我得到 200 Ok 状态。我的 PQL 代码中的主要错误是什么?
您应该将 body 作为由 & 符号连接的 urlencoded 字符串发送,而不是 JSON
所以body应该是这样的
body="grant_type=password&client_id=XXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=https%3A%2F%2FXXXXXXX%2Fhome%2F&username=user&password=password"