spring自带HTTP请求工具类的简单使用
2018-07-20 来源:open-open
spring包路径: org.springframework.http.client
try {
URI uri = new URI("http://192.168.129.11:7020/public/goIndex");
SimpleClientHttpRequestFactory schr = new SimpleClientHttpRequestFactory();
ClientHttpRequest chr = schr.createRequest(uri, HttpMethod.POST);
ClientHttpResponse res = chr.execute();
InputStream is = res.getBody(); //获得返回数据,注意这里是个流
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String str = "";
while((str = br.readLine())!=null){
System.out.println(str);//获得页面内容或返回内容
}
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
补充一下, maven工程只用到了spring-web
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Python布隆过滤器实现代码
下一篇:python实现ftp传输
最新资讯
热门推荐