Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.
目录
概述
HTTP请求是非常常见的一种需求。
需求:
1.URL管理
2. 网页下载器
3. 爬虫调度器
4. 网页解析器
5. 数据处理器
设计思路
实现思路分析
1.POST
String reqJsonStr = “{“code”:“testCode”, “group”:“testGroup”,“content”:“testContent”, “order”:1}”;
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity entity = new HttpEntity(reqJsonStr,headers);
ResponseEntity
2.(2)PUT请求
String reqJsonStr = “{“code”:“testCode”, “group”:“testGroup”,“content”:“testContent”, “order”:1}”;
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity entity = new HttpEntity(reqJsonStr,headers);
ResponseEntity
3.DELETE请求
ResponseEntity
4.GET请求
这个也比较简单,就是对网页元素进行解析,通常利用JSONP,xpath等技术进行网页分析。
5.数据处理器
ResponseEntity results = restTemplate.exchange(url,HttpMethod.GET, null, String.class, params);
说明
说明:1)url: 请求地址;
2)method: 请求类型(如:POST,PUT,DELETE,GET);
3)requestEntity: 请求实体,封装请求头,请求内容
4)responseType: 响应类型,根据服务接口的返回类型决定
5)uriVariables: url中参数变量值
参考资料和推荐阅读
- https://www.cnblogs.com/jnba/p/10522608.html
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!~