- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.util.EntityUtils;
- import java.io.IOException;
- public class Main {
- public static voidmain(String[] args)throws IOException{
- try {
- //创建client实例HttpClient client= HttpClients.createDefault();
- //创建httpget实例HttpGet httpGet=newHttpGet("http://www.btba.com.cn");
- //执行 get请求HttpResponse response=client.execute(httpGet);
- //返回获取实体HttpEntity entity=response.getEntity();
- //获取网页内容,指定编码String web= EntityUtils.toString(entity,"UTF-8");
- //输出网页
- System.out.println(web);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2003988.html