Spring的构造请求类 SimpleClientHttpRequestFactory

今天看到了Spring提供的SimpleClientHttpRequestFactory类,能够构造http request请求,下面是spring的doc地址

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/client/SimpleClientHttpRequestFactory.html

简单例子:

String url = "http://localhost:8080/clientRequestFacory/hello";
//构造请求对象
ClientHttpRequest request =new SimpleClientHttpRequestFactory().createRequest(new URI(url), HttpMethod.POST);
//设置请求头
request.getHeaders().set("Accept", "application/json");
//发送请求
ClientHttpResponse response = request.execute();








你可能感兴趣的:(Spring的构造请求类 SimpleClientHttpRequestFactory)