You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Power Query中发送表单数据的HTTP POST请求?

在Power Query中发送表单数据格式的POST请求

很简单,只需要调整请求头和请求体的格式就能实现,我给你直接改好代码并解释关键点:

基础版本代码

let
    url = "https://example.com",
    // 表单数据用键值对拼接,格式为 key1=value1&key2=value2
    body = "first_param=AAAAA&second_param=BBBBBB",
    Source = Json.Document(Web.Contents(url, [
        // 表单数据的Content-Type要改成 application/x-www-form-urlencoded
        Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
        Content = Text.ToBinary(body)
    ]))
in
    Source

特殊参数处理

如果你的参数值包含空格、中文、&这类特殊字符,一定要用Uri.EscapeDataString对参数值编码,避免请求解析出错,示例如下:

let
    url = "https://example.com",
    // 对含特殊字符的参数值进行URL编码
    param1 = Uri.EscapeDataString("AA AA 测试内容"),
    param2 = Uri.EscapeDataString("BB&BB=CC"),
    body = "first_param=" & param1 & "&second_param=" & param2,
    Source = Json.Document(Web.Contents(url, [
        Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
        Content = Text.ToBinary(body)
    ]))
in
    Source

和JSON请求的核心区别

  • 请求头的Content-Type从application/json替换为application/x-www-form-urlencoded
  • 请求体从JSON格式字符串改成了key=value拼接的表单格式,无需转义引号
  • 如果你的API要求multipart/form-data(比如上传文件场景),写法会更复杂,但普通表单提交用上面的格式就足够了

内容的提问来源于stack exchange,提问作者Mr.D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:38:35