---
title: "通过httpClient4读取页面内容"
author: "llying"
date: "2010-07-26T16:02:53Z"
tags: []
categories: ["编程语言"]
slug: "httpclient4"
draft: false
lastmod: "2010-07-26T16:02:53Z"
id: 721511
url: "https://llying.iteye.com/blog/721511"
---

```java

HttpClient httpClient = new DefaultHttpClient();
		HttpClientParams.setCookiePolicy(httpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY);  
		HttpHost httpHost = new HttpHost("localhost");
		HttpGet httpGet = new HttpGet("/https/");
		
		HttpResponse response = httpClient.execute(httpHost,httpGet);
		
		if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){
			//请求成功
			//取得请求内容
			HttpEntity entity = response.getEntity();
			//显示内容
			if (entity != null) {
				// 显示结果
			System.out.println(EntityUtils.toString(entity,"utf-8"));
			}
		}
		httpGet.abort();


```