如何使用Power Query的Web.Contents来打印多部分/表单数据 [英] How to POST a multipart/form-data using Power Query's Web.Contents
问题描述
__ rdxml=< *某些数据*>
那么你如何使用Web.Contents函数?
我尝试了,
。 ..
PostContent =__rdxml =< *一些数据*>,
源Web.Contents(url,Content = Text.ToBinary(PostContent))
...
但服务器响应与 400 Bad Request
p>
我用Fiddler检查了原始请求,似乎请求不是以 content-type = multipart / form-data
头。
我尝试手动添加内容类型标题与 content-type = multipart / form-data
,但是也不行。
任何想法?
multipart / form-data是一个相当复杂的编码,需要一堆MIME特定的头文件。我会首先尝试看看是否可以使用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
编辑:我想出了一个使用multipart / form-data的例子与电力查询。这是在 https://gist.github.com/CurtHagenlocher/b21ce9cddf54e3807317
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
"__rdxml"=<*Some data*>
So how do you do this using the Web.Contents function?
I tried, doing
...
PostContent = "__rdxml=<*Some data*>",
Source Web.Contents(url,Content=Text.ToBinary(PostContent))
...
But server response with 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.
I tried manually adding the content-type header with content-type=multipart/form-data
, but that doesn't work either. Same 400 Bad Request
in the response.
Any idea?
multipart/form-data is a fairly complicated encoding, requiring a bunch of MIME-specific headers. I would first try to see if you can use application/x-www-form-urlencoded instead:
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. It's at https://gist.github.com/CurtHagenlocher/b21ce9cddf54e3807317
这篇关于如何使用Power Query的Web.Contents来打印多部分/表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!