简而言之:我想使用 POST 方法将几个参数(例如 user=admin、key=12345678)发布到 PHP 页面(例如 localhost/post-debug.php)。该脚本将读取 $_POST 值并执行任何操作。
我的问题是:
1. 如何让下面的例子运行起来?
2. 如何从 JSON 编码的有效负载创建带有 POST 参数的地图有效负载并将其发送到 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>
我使用的是 MuleStudio 1.3.2、Mule ESB v.3.3。
我已经审查了许多类似的问题,但没有一个让我走上正轨。
这是问题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>
我使用以下方法来检查它是否正常工作:
curl -H "Content-Type: application/json" -d '{"param1":"value1","param2":"value2"}' http://localhost:8081/httpPost
请注意,我使用copy-properties
将 PHP 脚本调用的所有响应标头传播回原始调用者。如果你不介意的话就删除它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)