HttpClient网络链接工具类

package com.example.administrator.tv51365.utils;


import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by Administrator on 2016/3/1 0001.
 */
public class HttpConnection {
    public String GetWebConnection(String url) {
        String result=null;
        try {
            HttpGet get=new HttpGet(url);
            HttpClient client=new DefaultHttpClient();
            HttpResponse response=client.execute(get);
            if(response.getStatusLine().getStatusCode()==200){
                result= EntityUtils.toString(response.getEntity());
                System.out.println("HttpConnection**************************"+result);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;

    }
    }

猜你喜欢

转载自blog.csdn.net/briup_qiuqiu/article/details/50923152