简体   繁体   English

如何使用Power Query的Web发布目录/表单数据

[英]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.

相关问题 如何读取Power Query-&gt; Web.Contents响应标头? - How to read Power Query -> Web.Contents response header? 如何在Power Query中使用Web.Contents将列中的XML字符串转换为Web请求的Content - How to convert XML-string in column to Content for web request with Web.Contents in Power Query 将多部分/表单数据发布到端点 - Post multipart/form-data to endpoint 如何使用python中的POST请求在multipart/form-data中发送excel文件? - How to send excel file in multipart/form-data with POST Requests in python? Powershell:如何在多部分/表单数据请求中发布 excel (.xlsx) 文件? - Powershell: How can I POST excel (.xlsx) files in a multipart/form-data request? VBA发布请求错误-多部分/表单数据 - VBA post request error - multipart/form-data Web.Contents() 在 for 循环 VBA 中更新 URL - Web.Contents() update URL in a for loop VBA 如何使用 WinHTTPRequest 在 Excel 中使用 VBA 发送表单数据 POST 请求 - How to send a form-data POST request with VBA in Excel using WinHTTPRequest 如何使用 Power Query 从 Web 动态检索数据到 Excel - How to dynamically retrieve data from web to excel using Power Query Power Query,使用表单数据发出 http POST 请求 - Power Query, make http POST request with form data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM