您的位置:首页 > 理论基础 > 计算机网络

Spring的构造请求类 SimpleClientHttpRequestFactory

2016-05-05 23:33 471 查看
今天看到了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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: