package com.httpclient;
import java.io.InputStream;
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;
/*************************************************
* @author tangzs 2014-04-14
* 发送简单 HttpClient 请求 http://www.baidu.com
*************************************************/
@SuppressWarnings("deprecation")
public class Main1 {
public static void main(String[] args) throws Exception {
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet("http://www.baidu.com");
HttpResponse response = httpClient.execute(get);
HttpEntity entity = response.getEntity();
///
if (entity != null) {
InputStream instream = entity.getContent();
@SuppressWarnings("unused")
int l;
byte[] tmp = new byte[2048];
while ((l = instream.read(tmp)) != -1) {
System.out.println("=========>>"+tmp.toString());
}
}
}
}
import java.io.InputStream;
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;
/*************************************************
* @author tangzs 2014-04-14
* 发送简单 HttpClient 请求 http://www.baidu.com
*************************************************/
@SuppressWarnings("deprecation")
public class Main1 {
public static void main(String[] args) throws Exception {
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet("http://www.baidu.com");
HttpResponse response = httpClient.execute(get);
HttpEntity entity = response.getEntity();
///
if (entity != null) {
InputStream instream = entity.getContent();
@SuppressWarnings("unused")
int l;
byte[] tmp = new byte[2048];
while ((l = instream.read(tmp)) != -1) {
System.out.println("=========>>"+tmp.toString());
}
}
}
}