Apache Came组件http4的使用
2015-09-11 12:02
615 查看
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调用
示例二:https调用
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>http://www.oschina.net/action/openapi/news_list</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>https://www.oschina.net/action/oauth2/authorize</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>
相关文章推荐
- C++ 用libcurl库进行http通讯网络编程
- Http Post get
- Http Post Get
- 关于 HTTP GET/POST 请求参数长度最大值的问题
- iOS 基于Socket 的 C/S 网络通信结构(下一个)
- Android Https相关完全解析 当OkHttp遇到Https
- iOS开发小白学习体验-7-网络请求
- python3.4.3 调用http接口 解析response xml后插入数据库
- jmeter学习笔记(1)——http default request的用法
- Linux网络编程--非阻塞编程
- HTTP - Cookie 机制
- Android网络编程之使用HTTP访问网络资源
- 微信支付---申请退款的https双向认证demo
- 连接网络
- android的网络通讯(Http通讯)封装类
- Linux网络编程--poll()和ppoll()函数
- httpclient4 post请求传参数
- 常见网络编程面试题(一)
- 各类 HTTP 返回状态代码详解
- 如何设置CentOS 5的yum源[上海交通大学http://ftp.sjtu.edu.cn/centos/5.0/os/x86_64]