Mule ESB-如何通过HTTP POST方法调用API(一起发送参数) [英] Mule ESB - How to call a API via HTTP POST method (sending parameters along)

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

问题描述

又是我.

我正在尝试创建一个流程,该流程会将职位空缺发布到职位门户.他们通过Post方法公开其API.我不确定如何将值传递到HTTP端点. 这只是其中包含硬编码值的测试样本.当它起作用时,我将让流程从数据库中提取值.

I am trying to create a flow that will post a a job opening to a job portal. They expose their API via a Post method. I am not sure how to pass the values to the HTTP end-point. This is just a testing sample with hard coded values in it. when it works will I have the flow pick-up the values from a database.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" 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="EE-3.4.2"
        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
    http://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd">
        <http:connector name="HTTP_CONFIG" cookieSpec="netscape" validateConnections="false" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="100000" serverSoTimeout="100000" socketSoLinger="0" proxyHostname="pta-proxy.work.co.za" proxyPort="3128" doc:name="HTTP\HTTPS" />
        <flow name="career24Flow1" doc:name="career24Flow1">
            <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP" contentType="text/plain"/>       
            <message-properties-transformer  doc:name="Set the  post Values" >
                <add-message-property key="apikey" value="XXXX"/>
                <add-message-property key="integrationkey" value="567"/>
                <add-message-property key="consultantemail" value="integrations@work.com"/>
                <add-message-property key="title" value="Testing Mule API"/>
                <add-message-property key="reference" value="33175"/>
                <add-message-property key="jobtypeid" value="1"/>
                <add-message-property key="closingdate" value="01/06/2014"/>
                <add-message-property key="location" value="66"/>
                <add-message-property key="salaryfrom" value="10000.00"/>
                <add-message-property key="salaryto" value="20000.00"/>
                <add-message-property key="salaryunitid" value="4"/>
                <add-message-property key="description" value="Testing the Mule ESB to post to the portal"/>
                <add-message-property key="companyname" value="CSIR"/>
                <add-message-property key="sectorids" value="17"/>
                <add-message-property key="applicationmethodid" value="2"/>
                <add-message-property key="applicationurl" value="http://www.testing.com"/>
                <add-message-property key="package" value="2"/>
            </message-properties-transformer>
            <http:outbound-endpoint exchange-pattern="request-response" host="api.work.com" port="80" method="POST" doc:name="Post on Career24"  path="_integrations/httppost/vacancy.ashx" connector-ref="HTTP_CONFIG" contentType="application/x-www-form-urlencoded"/>

        </flow>
    </mule>

我从网站取回了它,因此似乎没有通过HTTP端点发送值.

I get this back from the site so it seems the values are not being sent via the HTTP end-point.

ERROR:
- Field &#39;apikey&#39;, is required.
- Field &#39;integrationkey&#39;, is required.
- Field &#39;consultantemail&#39;, is required.
- Field &#39;title&#39;, is required.
- Field &#39;reference&#39;, is required.
- Field &#39;jobtypeid&#39;, is required.
- Field &#39;closingdate&#39;, is a required field.
- Field &#39;sectorids&#39;, is required.
- Field &#39;location&#39;, is required.
- Field &#39;description&#39;, is required.
- Field &#39;applicationmethodid&#39;, is required.

我也尝试了消息到HTTP响应"转换器,但还是没有运气.

I have tried a "Message to HTTP Response" transformer as well but still no luck.

感谢您的帮助.

致谢.

Jaco.

推荐答案

使用带有http出站终结点的属性会将它们设置为http标头.相反,您需要Map类型的有效负载才能将它们设置为POST变量.

Using properties with http outbound endpoint will set them as http headers. Instead you need a payload of type Map to set them as POST variables.

赞:

<set-payload value="#[['xxx':'yyy']]"/>

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

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