【发布时间】:2021-09-09 20:18:00
【问题描述】:
我尝试通过 Excel Power Query 连接到云上的 db2。
基于documentation,这是 curl 请求的格式:
curl -X POST https://hostname.com/dbapi/v4/sql_query_export -H 'authorization: Bearer MyToken' -H 'content-type: text/csv' -d '{"command":"select * from mytable"}'
我很确定我做的不对,但我什至无法谷歌如何传递我的参数。
有人可以指导如何为此组装 M 代码吗?
我根据@nfgl 的回答试过了
let
body = [#"command"="select * from mytable"]
,json = Json.FromValue(body)
,wc = Web.Contents("https://hostname.com/dbapi/v4/sql_query_export", [Headers=[#"content-type"="text/csv", authorization="Bearer XXX"]])
,Source = Csv.Document(wc,[Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv])
in
Source
顺便说一句,一切都适用于 python:
import http.client
conn = http.client.HTTPSConnection("hostname.com")
payload = "{\"command\":\"select * from mytable\"}"
headers = {
'content-type': "text/csv",
'authorization': "Bearer XXX"
}
conn.request("POST", "/dbapi/v4/sql_query_export", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
【问题讨论】:
-
您可能想从您的问题中删除凭据...
-
那些是假的,但还是谢谢。
标签: api db2 powerquery rest