httpclient 入门1

package com;

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.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Test {
	public static void main(String args[]) throws Exception, Exception{
	HttpClient httpclient = new DefaultHttpClient();
	HttpGet httpget=new HttpGet("http://172.20.32.60:8080/tom/");
	HttpResponse response= httpclient.execute(httpget);
	HttpEntity entity =response.getEntity();

	if(entity !=null){

		long len = entity.getContentLength();
		if (len != -1 && len < 2048) {
		System.out.println(EntityUtils.toString(entity));
		} else {
//		 Stream content out

		}
	}
}}
 

你可能感兴趣的:(apache)