Spring RestTemplate 小结
关于RestTemplate
首先,你可以把它理解为一个发起请求并接收响应的工具类(功能类似浏览器)。
其次,它其实是一个壳,具体还是通过调用别的接口来实现(如jdk自带的连接,或者HttpClient之类的,需要设置)。
Spring's central class for synchronous client-side HTTP access.
It simplifies communication with HTTP servers, and enforces RESTful principles.
It handles HTTP connections, leaving application code to provide URLs (with possible template variables) and extract results. Note: by default the RestTemplate relies on standard JDK facilities to establish HTTP connections.
You can switch to use a different HTTP library such as Apache HttpComponents, Netty, and OkHttp
through the HttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) property.
使用
这个其实没什么说的,不外乎创建template,设置底层连接,然后增删改查。
请参考Spring REST和 RestTemplate实践。
唯一需要注意的就是默认的jdk连接是不支持delete带请求体--解决办法见下面链接。
其他
暂时不清楚使用RestTemplate和直接使用HttpClient有什么区别,感觉HttpClient足够用了--囧。
--突然想到的,RestTemplate可以配合MessageConverter等使用!!!也就是配合SpringMVC使用,而HttpClient则需要手动转换!
杂:
httpHeaders.add("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6");
q是权重系数,范围 0 =< q <= 1,q 值越大,请求越倾向于获得其“;”之前的类型表示的内容,若没有指定 q 值,则默认为1,若被赋值为0,则用于提醒服务器哪些是浏览器不接受的内容类型。
参考:
通过 Spring RestTemplate 调用带请求体的 Delete 方法(Delete With Request Body)
为你详细解读HTTP请求头的具体含意
网页头部的声明应该是用 lang="zh" 还是 lang="zh-cn"?
HttpClient使用详解
RestTemplate实践
Spring REST
HttpClient使用详解
另推荐一个好文
SpringMVC源码剖析(五)-消息转换器HttpMessageConverter
Spring RestTemplate 小结的更多相关文章
- Spring RestTemplate: 比httpClient更优雅的Restful URL访问, java HttpPost with header
{ "Author": "tomcat and jerry", "url":"http://www.cnblogs.com/tom ...
- Spring RestTemplate介绍
http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...
- How to Send an HTTP Header With Every Request With Spring RestTemplate
In Know Which Apps Are Hitting Your Web Service, I showed how to write a servlet filter that enforce ...
- Spring RestTemplate详解
Spring RestTemplate详解 1.什么是REST? REST(RepresentationalState Transfer)是Roy Fielding 提出的一个描述互联系统架构风格 ...
- Spring RestTemplate中几种常见的请求方式GET请求 POST请求 PUT请求 DELETE请求
Spring RestTemplate中几种常见的请求方式 原文地址: https://blog.csdn.net/u012702547/article/details/77917939 版权声明 ...
- How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查)
How to disable SSL certificate checking with Spring RestTemplate?(使用resttemplate访问https时禁用证书检查) **** ...
- spring RestTemplate用法详解
spring RestTemplate用法详解 spring 3.2.3 框架参考有说明 21.9 Accessing RESTful services on the Client
- 使用HttpClient4来构建Spring RestTemplate
Spring RestTemplate简单说明 现在REST服务已经很普及了,在我们的程序中,经常会需要调用REST API,这时候会有很多选择,原始一点的JDK自带的,再进一步点使用HttpClie ...
- spring restTemplate 用法
发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...
随机推荐
- [hihoCoder] #1122 : 二分图二•二分图最大匹配之匈牙利算法
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上一回我们已经将所有有问题的相亲情况表剔除了,那么接下来要做的就是安排相亲了.因为过年时间并不是很长,所以姑姑希望能够尽可 ...
- [hihoCoder] #1089 : 最短路径·二:Floyd算法
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 万圣节的中午,小Hi和小Ho在吃过中饭之后,来到了一个新的鬼屋! 鬼屋中一共有N个地点,分别编号为1..N,这N个地点之间 ...
- mybatis 一二事(3) - 多表关联查询
db.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/order jdbc.user ...
- C# winform 多线程异步操作线程启动暂停与恢复
/// <summary> /// 线程控制模块 /// </summary> private ManualResetEvent manualResetEvent = new ...
- Linux写时拷贝技术(copy-on-write)
1.传统的fork()函数创建一个子进程,子进程和父进程共享正文段,复制数据段,堆,栈到子进程示意图如下: 2.Linux的fork()函数-写时复制(copy-on-write)创建一个子进程,内核 ...
- hdoj1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 【HBase】Rowkey设计【转】
本章将深入介绍由HBase的存储架构在设计上带来的影响.如何设计表.row key.column等等,尽可能地使用到HBase存储上的优势. Key设计 HBase有两个基础的主键结构:row key ...
- 将ip地址转换成C段地址的UDF
将ip地址转换成C段地址的UDF,最重要的是判断IP地址的正则表达式. package cn.cnnic.ops.Study; import java.util.regex.Pattern; impo ...
- Class.getName和Class.getCanonicalName的区别
对于一般的type来说,这二者没有区别,对于array和inner type,就有区别了,可以写代码亲测,如下: package simple; class Box { class Inner {} ...
- .NET项目web自动化测试实战——Selenium 2.0
PS:这次用公司的项目来练手,希望公司不会起诉我,因为我绝对是抱着学习的态度,没有任何恶意.仅供交流学习. 该项目是基于SharePoint平台所开发的门户网站,为了切身感受一下Selenium 2. ...