springboot管理的项目,自动发送HTTP请一个自动网页获取图片链接,首先考虑到用HTTPClient API,经同事指点用了springboot自带的API,代码非常简洁,两行代码如下。
RestTemplate restTemplate = new RestTemplate;
String forObject = restTemplate.getForObject(url,String.class);
环境Spring Boot
pom.xml (核心内容)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependencies>
---------------------
restTemplate.getForObject(url, String.class); // 向url发送 Get类型请求,将返回结果 以String类型显示 // 能很明显发现无法设置编码格式等&