gpt4 book ai didi

http - 在 Mule 3.1.2 中代理 HTTP POST 表单数据

转载 作者:可可西里 更新时间:2023-11-01 16:45:14 24 4
gpt4 key购买 nike

我需要将一些发布数据发送到 mule 3.1.2 中的另一台服务器。这是我的 mule-config 文件:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:rmi="http://www.mulesoft.org/schema/mule/rmi" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.1/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.1/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/rmi http://www.mulesoft.org/schema/mule/rmi/3.1/mule-rmi.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.1/mule-stdio.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd">

<flow name="cxfFlow">
<!-- Accept a http request from the specific address -->
<http:inbound-endpoint address="http://localhost:5678/httpHello">
<byte-array-to-string-transformer/>
<http:body-to-parameter-map-transformer/>
</http:inbound-endpoint>

<!-- This component is just set to show the message accecpted from the request -->
<scripting:component>
<scripting:script engine="groovy">
def msg = "message: $message;\npayload:$payload;\n result:$result".toString()
println msg
println "init param:$payload"
return payload
</scripting:script>
</scripting:component>

<!-- This component is set to parse the parameter passed by the request -->
<scripting:component>
<scripting:script engine="groovy">
def paramstr = ""
for( param in payload){
paramstr = paramstr + "&amp;" + param.key+ "=" + param.value
}
println "querystr:$paramstr"
return paramstr.substring(1)
</scripting:script>
</scripting:component>

<choice>
<when expression="payload.size()>0" evaluator="groovy">
<http:outbound-endpoint address="http://localhost:8080/webproj/index.jsp" method="POST" contentType="text/http">
</http:outbound-endpoint>
</when>
<otherwise>
<scripting:component>
<scripting:script engine="groovy">
println payload
return "no parameter is given!"
</scripting:script>
</scripting:component>
</otherwise>
</choice>
</flow>
</mule>

我向 http://localhost:5678/httpHello 发送了一个帖子请求, 并发送一些参数。在http://localhost:8080/webproj/index.jsp页面,我检查收到的参数,但参数为空。我想在 index.jsp 页面中接收开头发送的参数,如何更改我的 mule-config 文件?非常感谢!

最佳答案

假设入站和出站 HTTP 内容类型是application/x-www-form-urlencoded,这是一个执行您想要的操作的配置(即记录有效负载并选择不同的响应基于参数的存在):

<flow name="webFormFlow">
<!-- Accept a http request from the specific address -->
<http:inbound-endpoint address="http://localhost:5678/httpHello">
<http:body-to-parameter-map-transformer />
</http:inbound-endpoint>

<!-- This logger is just set to show the message accepted from the request -->
<logger level="INFO" message="#[payload]" />

<choice>
<when expression="payload.size() &gt; 0" evaluator="groovy">
<http:outbound-endpoint address="http://localhost:8080/webproj/index.jsp"
method="POST" contentType="application/x-www-form-urlencoded" />
</when>
<otherwise>
<message-properties-transformer>
<add-message-property key="Content-Type" value="text/plain" />
</message-properties-transformer>
<expression-transformer>
<return-argument expression="no parameter is given!"
evaluator="string" />
</expression-transformer>
</otherwise>
</choice>
</flow>

关于http - 在 Mule 3.1.2 中代理 HTTP POST 表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8532700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com