spring自带HTTP请求工具类的简单使用

只为记录一下,  直接上代码, 都能看明白 , 若有遗留,请谅解, 

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>


文章来自:http://my.oschina.net/goulin/blog/497228
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3