您的位置:首页 > 理论基础 > 计算机网络

HttpClient网络链接工具类

2016-03-18 14:21 246 查看
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;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: