Apache Came组件http4的使用

编程入门 行业动态 更新时间:2024-10-05 15:28:41

Apache Came<a href=https://www.elefans.com/category/jswz/34/1771375.html style=组件http4的使用"/>

Apache Came组件http4的使用

http : For calling out to external HTTP servers using Apache HTTP Client 3.x

http4 : For calling out to external HTTP servers using Apache HTTP Client 4.x

其实是一样的,只是底层用的http client版本不一样


现在以http4为例子


示例一:http调用


<route><from uri="direct://start-http" /><!-- 指定提交方式 --><setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader><!-- 指定请求参数 --><setHeader headerName="CamelHttpQuery"><constant>account=hongshu&client_id=111111&response_type=code</constant></setHeader><!-- 指定请求地址 --><setHeader headerName="CamelHttpUri"><constant>;/constant></setHeader><!-- 指定请求的编码方式 --><setProperty propertyName="CamelCharsetName"><constant>UTF-8</constant></setProperty><!-- 执行(调用完成后,body是inputStream,转换成string即可) --><to uri="http4://http" /><!-- 转换成string --><convertBodyTo type="java.lang.String" charset="UTF-8" /><to uri="log:show?showAll=true&multiline=true" />
</route>




示例二:https调用

<!-- 配置ssl证书 -->
<camel:sslContextParameters id="sslContextParameters"><camel:trustManagers><camel:keyStore resource="/opt/ssl/key/cacerts.jks" password="changeit" /></camel:trustManagers>
</camel:sslContextParameters><route><from uri="direct://start-http" /><!-- 指定提交方式 --><setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader><!-- 指定请求参数 --><setHeader headerName="CamelHttpQuery"><constant>account=hongshu&client_id=111111&response_type=code</constant></setHeader><!-- 指定请求地址 --><setHeader headerName="CamelHttpUri"><constant>;/constant></setHeader><!-- 指定请求的编码方式 --><setProperty propertyName="CamelCharsetName"><constant>UTF-8</constant></setProperty><!-- 执行,并且指定ssl的证书路径 (调用完成后,body是inputStream,转换成string即可)--><to uri="http4://http?sslContextParametersRef=sslContextParameters" /><to uri="log:show?showAll=true&multiline=true" />
</route>


更多推荐

Apache Came组件http4的使用

本文发布于:2024-02-14 15:06:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!