zoukankan      html  css  js  c++  java
  • Apache HttpClient FirstDemo

    import java.io.InputStream;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    
    
    /**
     * 
     * FileName HttpDemo.java  <br />
     * @author wenhao <br />
     * @version 1.0   <br />
     * @created 2013-1-10 下午7:02:08 <br />
     * 
     */
    
    /**
     * 
     * @author wenhao <br />
     * @version 1.0   <br />
     * @created 2013-1-10 下午7:02:08 <br />
     * 
     */
    public class HttpDemo {
        
        public static void main(String args[]) throws Exception{
            DefaultHttpClient http = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet("http://172.20.223.120/wenhao.txt");
            HttpResponse response = http.execute(httpGet);
            
            try {
                System.out.println(response.getStatusLine());
                HttpEntity entity = response.getEntity();
                InputStream input = entity.getContent();
                
                byte[] buf = new byte[1024];
                int len = input.read(buf);
                
                System.out.println(new String(buf, 0, len));
                EntityUtils.consume(entity);
            } catch (Exception e) {
                // TODO: handle exception
            } finally{
                httpGet.releaseConnection();
            }
        }
    
    }
  • 相关阅读:
    python 基础第二篇
    python 基础第五篇
    python 基础第四篇
    购物小编程(完整编码)
    计算机 python概论
    str 相关操作
    python 基础第三篇
    Nginx 配置多站点vhost
    h5页面宽度设置7.5rem
    js 倒计时,转义
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2855383.html
Copyright © 2011-2022 走看看