作者:陈玲琳2013 | 来源:互联网 | 2023-05-16 14:55
1.下载apche官网下方project列表中的HttpComponents的Binary2.下载后解压,将lib文件夹中的文件导入工程并且buildpath3.代码:import
1.下载apche官网下方project列表中的HttpComponents的 Binary
2.下载后解压,将lib文件夹中的文件导入工程并且buildpath
3.代码:
import java.io.IOException
import org.apache.http.HttpEntity
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.HttpClients
import org.apache.http.util.EntityUtils
public class TestGet {
public static void main(String[] args) {
// TODO Auto-generated method stub
new Get().start()
}
}
class Get extends Thread {
HttpClient client = HttpClients.createDefault()
public void run() {
HttpGet get = new HttpGet("http://www.baidu.com")
try {
HttpResponse respOnse= client.execute(get)
HttpEntity entity = response.getEntity()
String result = EntityUtils.toString(entity, "UTF-8")
System.out.println(result)
} catch (ClientProtocolException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}
}
}
结果:完整的html数据