Mule ESB-如何使用POST方法创建HTTP请求(一起发送参数) [英] Mule ESB - How to create a HTTP request with POST method (sending parameters along)

查看:123
本文介绍了Mule ESB-如何使用POST方法创建HTTP请求(一起发送参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Short: I want to post a couple of parameters (like user=admin, key=12345678) using the POST method to a PHP page (like localhost/post-debug.php). The script would read the $_POST values and do whatever.

我的问题是:

1.如何使下面的示例起作用?

2.如何通过JSON编码的有效负载中的POST参数创建地图有效负载并将其发送到PHP脚本?

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

Below is an isolated case I am trying to get running (the parameters are "read" from the HTTP endpoint). I am calling directly from the browser the following 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.

I am using MuleStudio 1.3.2, Mule ESB v.3.3.

我已经审查了许多类似的问题,但没有一个让我步入正轨.

I've reviewed many similar questions but none got me on the right track.

推荐答案

这是问题2的解决方案(回答问题1不会有帮助):

Here is the solution for question 2 (answering question 1 won't help):

<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>

我使用以下方法检查它是否正常运行:

I've used the following to check it works fine:

curl -H "Content-Type: application/json" -d '{"param1":"value1","param2":"value2"}' http://localhost:8081/httpPost

请注意,我使用copy-properties将所有响应标头从PHP脚本调用传播回原始调用者.如果您不在乎,请将其删除.

Note that I use copy-properties to propagate all the response headers from the PHP script invocation back to the original caller. Remove it if you don't care.

这篇关于Mule ESB-如何使用POST方法创建HTTP请求(一起发送参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆