【问题标题】:Mule 4 : HTTP Requester : How to send multipart/form-data as POST Body for Mule REST Service Call?Mule 4:HTTP 请求者:如何将 multipart/form-data 作为 Mule REST 服务调用的 POST 正文发送?
【发布时间】:2021-10-07 14:11:48
【问题描述】:

场景:

我必须从 Mule 4 内部进行 REST 服务调用,并将 multipart/form-data 作为 POST Body 发送。

为了在 Dataweave 中形成多部分/表单数据,我执行了以下操作:

%dw 2.0
output multipart/form-data 
---
{
    parts: {
        Field1: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value1"
        },
        Field2: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value2"
        },
        Field3: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value3"
        }
    }
}

然后在 HTTP 请求中,我在 HTTP 请求者正文中设置了有效负载。

但是当我进行 REST API 调用时,我收到了错误 Missing Field1

有什么办法可以解决这个问题?

【问题讨论】:

  • 请显示完整的 XML sn-p(转换,HTTP 请求)和从日志中复制的完整错误消息以及所有详细信息。

标签: multipartform-data dataweave rest mule4


【解决方案1】:

这对我来说很好用:

        <ee:transform doc:name="Transform Message">
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data 
---
{
    parts: {
        Field1: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value1"
        },
        Field2: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value2"
        },
        Field3: {
            headers : {
                "Content-Type": "text/plain"
            },
            content: "Value3"
        }
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <http:request method="POST" doc:name="Request" config-ref="HTTP_Request_configuration" path="/backend" >
        </http:request>

【讨论】:

  • 请求没有错误。实际上我需要将参数作为 url 编码的表单参数而不是多部分表单数据发送。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多