• [HttpClient]简单使用GET请求


    package com.jerry.httpclient;
    
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.util.EntityUtils;
    
    /**
     * 
     * @author Jerry
     * @date 2015年2月11日 下午10:58:44
     */
    public class FirstDemo {
        public static void main(String[] args) {    
            CloseableHttpClient client = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet("http://www.baidu.com");
            CloseableHttpResponse response = null;
            try {
                response = client.execute(httpGet);
                System.out.println(response.getStatusLine());
                HttpEntity entity = response.getEntity();
                System.out.println(EntityUtils.toString(entity));
                EntityUtils.consume(entity);//关闭httpEntity的的输入流
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                try {
                    if (response != null) {
                        response.close();    
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    response = null;
                }
            }
            
        }
    }
  • 相关阅读:
    ODBC接口规范
    JDBC与ODBC
    java中newInstance()和new()
    JDBC详解
    用JDBC连接 数据库 进行简单的增删改查
    JDBC接口规范
    JDBC中常用的接口
    java中的getStackTrace和printStackTrace的区别
    linux中的strings命令
    JAVA的容器---List,Map,Set (转)
  • 原文地址:https://www.cnblogs.com/jerry19890622/p/4290916.html
Copyright © 2020-2023  润新知