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>
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10559.html