[英]How to POST a multipart/form-data using Power Query's Web.Contents
In Power Query, I can download data from Web using the Web.Contents function, but there's an api that required the request to contains multipart/form data in the following format 在Power Query中,我可以使用Web.Contents函数从Web下载数据,但是有一个api要求请求包含以下格式的多部分/表单数据
"__rdxml"=<*Some data*>
So how do you do this using the Web.Contents function? 那么如何使用Web.Contents函数来做到这一点呢?
I tried, doing 我尝试过
...
PostContent = "__rdxml=<*Some data*>",
Source Web.Contents(url,Content=Text.ToBinary(PostContent))
...
But server response with 400 Bad Request
. 但是服务器响应为
400 Bad Request
。
I checked the raw request with Fiddler, it seem like the request is not sending with content-type=multipart/form-data
header. 我用Fiddler检查了原始请求,似乎该请求未使用
content-type=multipart/form-data
标头发送。
I tried manually adding the content-type header with content-type=multipart/form-data
, but that doesn't work either. 我尝试用
content-type=multipart/form-data
手动添加content-type标头,但这也不起作用。 Same 400 Bad Request
in the response. 响应中的相同
400 Bad Request
。
Any idea? 任何想法?
multipart/form-data is a fairly complicated encoding, requiring a bunch of MIME-specific headers. multipart / form-data是一种相当复杂的编码,需要一堆特定于MIME的标头。 I would first try to see if you can use application/x-www-form-urlencoded instead:
我首先尝试看看您是否可以使用application / x-www-form-urlencoded代替:
let
actualUrl = "http://some.url",
record = [__rdxml="some data"],
body = Text.ToBinary(Uri.BuildQueryString(record)),
options = [Headers =[#"Content-type"="application/x-www-form-urlencoded"], Content=body],
result = Web.Contents(actualUrl, options)
in
result
EDIT: I've come up with an example of using multipart/form-data with Power Query. 编辑:我想出了一个使用Power Query的multipart / form-data的示例。 It's at https://gist.github.com/CurtHagenlocher/b21ce9cddf54e3807317
在https://gist.github.com/CurtHagenlocher/b21ce9cddf54e3807317
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.