Mule ESB - 如何使用POST方法创建HTTP请求(发送参数)

Val*_*spa 2 mule mule-studio

简:我想使用POST方法将一些参数(例如user = admin,key = 12345678)发布到PHP页面(如localhost/post-debug.php).该脚本将读取$ _POST值并执行任何操作.

我的问题是:

1.我怎样才能让下面的例子起作用?

2.如何使用JSON编码的有效负载中的POST参数创建Map Payload并将其发送到PHP脚本?

下面是一个我试图运行的独立案例(参数是从HTTP端点"读取").我直接从浏览器调用以下URL:

http://localhost:8081/httpPost?user=admin&key=12345678

多流量

基础XML:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
    <flow name="httpPostTestFlow1" doc:name="httpPostTestFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="httpPost" doc:name="HTTP"/>
            <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>

        <echo-component doc:name="Echo"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost/post-debug.php" port="80"  contentType="application/x-www-form-urlencoded" doc:name="HTTP" />
    </flow>
</mule>
Run Code Online (Sandbox Code Playgroud)

我使用的是MuleStudio 1.3.2,Mule ESB v.3.3.

我已经回顾了许多类似的问题,但没有一个让我走上正轨.

Dav*_*sot 7

这是问题2的解决方案(回答问题1无济于事):

<flow name="httpPostTestFlow1">
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8081" path="httpPost" />
    <json:json-to-object-transformer
        returnClass="java.util.Map" />
    <http:outbound-endpoint exchange-pattern="request-response"
        host="localhost" port="80" path="post-debug.php" method="POST"
        contentType="application/x-www-form-urlencoded" />
    <copy-properties propertyName="*" />
</flow>
Run Code Online (Sandbox Code Playgroud)

我用以下内容检查它是否正常工作:

curl -H "Content-Type: application/json" -d '{"param1":"value1","param2":"value2"}' http://localhost:8081/httpPost
Run Code Online (Sandbox Code Playgroud)

请注意,我用来copy-properties将PHP脚本调用中的所有响应头传播回原始调用者.如果你不在乎,请将其取下.