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

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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>