1.
Features:
-
Standards-based, pure Java language. Realized Http1.0 and Http1.1
-
In object-oriented extensible structure achieved full Http method (GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE)
-
Support for HTTPS protocol.
-
Http establish a transparent connection through a proxy.
- Automatic Processing Set-Cookie Cookie.
2 This interface returns a User object, but we have to be the actual Json string User needs me, and we manually into the User object at this time can make use of the Spring RestTemplate
@Test
public void testGetPojo() throws IOException {
HttpGet request = new HttpGet("http://localhost/hello");
String response = this.httpClient.execute(request, new BasicResponseHandler());
System.out.println(response);
}
3.
@Bean
public Residual Template rest template () {
return new Rest Template ();
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HttpDemoApplication.class)
public class HttpDemoApplicationTests {
@Autowired
private RestTemplate restTemplate;
@Test
public void httpGet() {
User user = this.restTemplate.getForObject("http://localhost:8080/User/1.html", User.class);
System.out.println(user);
}
}