1.项目结构

导入jar包

jar包去官网下载
解压后项目新建lib目录,将解压包中的lib目录中的zip拷入项目lib目录文件夹,然后build path-->配置到项目中

2.TestGet.java

package testhttpclient;

import java.io.IOException;

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;
/**
* 使用HttpGet方法获取网页数据
* @author xjj13
*
*/
public class TestGet {
public static void main(String[] args) {
new Get().start();
}
}
class Get extends Thread{
//创建标准的httpClient
HttpClient client=HttpClients.createDefault();
@Override
public void run() {
HttpGet get=new HttpGet("http://www.baidu.com");
try {
//执行
HttpResponse response=client.execute(get);
//http实例化对象
HttpEntity entity=response.getEntity();
String result=EntityUtils.toString(entity, "UTF-8");

System.out.println(result);

} catch (IOException e) {
e.printStackTrace();
}
}

}
3.项目运行结果

新建test.xml,拷贝console内容如下:

<!DOCTYPE html>
<!--STATUS OK -->
<html>
<head>
<meta http-equiv=content-type content=text/html;charset=utf-8>
<meta http-equiv=X-UA-Compatible content=IE=Edge>
<meta content=always name=referrer>
<link rel=stylesheet type=text/css
href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
<title>百度一下,你就知道</title>
</head>
<body link=#0000cc>
<div id=wrapper>
<div id=head>
<div class="head_wrapper">
<div class="s_form">
<div class="s_form_wrapper">
<div id=lg>
<img hidefocus=true src=//www.baidu.com/img/bd_logo1.png
width=270 height=129>
</div>
<form id=form name=f action=//www.baidu.com/s class="fm">
<input type=hidden name=bdorz_come value=1>
<input type=hidden name=ie value=utf-8>
<input type=hidden name=f value=8>
<input type=hidden name=rsv_bp value=1>
<input type=hidden name=rsv_idx value=1>
<input type=hidden name=tn value=baidu>
<span class="bg s_ipt_wr">
<input id=kw name=wd class="s_ipt" value
maxlength=255 autocomplete=off autofocus>
</span>
<span class="bg s_btn_wr">
<input type=submit id=su value=百度一下
class="bg s_btn">
</span>
</form>
</div>
</div>
<div id=u1>
<a href=http://news.baidu.com name=tj_trnews class="mnav">新闻</a>
<a href=http://www.hao123.com name=tj_trhao123 class="mnav">hao123</a>
<a href=http://map.baidu.com name=tj_trmap class="mnav">地图</a>
<a href=http://v.baidu.com name=tj_trvideo class="mnav">视频</a>
<a href=http://tieba.baidu.com name=tj_trtieba class="mnav">贴吧</a>
<noscript>
<a
href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1
name=tj_login class="lb">登录</a>
</noscript>
<script>
document.write('
<a
href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === " "
: " bdorz_come=1 " name="tj_login" class="lb">登录</a>
');
</script>
<a href=//www.baidu.com/more / name=tj_briicon class="bri"
style="display: block;">更多产品</a>
</div>
</div>
</div>
<div id=ftCon>
<div id=ftConw>
<p id=lh>
<a href=http://home.baidu.com>关于百度</a>
<a href=http://ir.baidu.com>About Baidu</a>
</p>
<p id=cp>&copy;2017&nbsp;Baidu&nbsp;
<a href=http://www.baidu.com/duty />
使用百度前必读
</a>&nbsp;
<a href=http://jianyi.baidu.com / class="cp-feedback">意见反馈</a>&nbsp;京ICP证030173号&nbsp;
<img src=//www.baidu.com/img/gs.gif>
</p>
</div>
</div>
</div>
</body>
</html>

使用HttpClient进行Get方式通信(使用HttpGet获取网页数据)的更多相关文章

  1. UWP 使用HttpClient获取网页数据

    我的App自然灾害中,为了展示地震的各种信息,就需要从网页上获取地震源数据. 如图所示,我们需要展示 地震等级.地震发生时间.经纬度.震源深度.地震位置等信息. 那么,假设给了一个地震的源,中国地震台 ...

  2. 使用HttpClient进行Get方式通信

    下载apache包 http://hc.apache.org/downloads.cgi 比较eclipse自带api,简单,易上手 实例: package zw1; import java.io.I ...

  3. 使用 HttpClient 进行 Post 方式通信

    1.TestPost.java package testhttpclient; import java.io.IOException;import java.util.ArrayList;import ...

  4. Asp.Net Core中HttpClient的使用方式

    在.Net Core应用开发中,调用第三方接口也是常有的事情,HttpClient使用人数.使用频率算是最高的一种了,在.Net Core中,HttpClient的使用方式随着版本的升级也发生了一些变 ...

  5. 07_android入门_採用HttpClient的POST方式、GET方式分别实现登陆案例

    1.简单介绍 HttpClient 是 Apache Jakarta Common 下的子项目,能够用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,而且它支持 HTTP 协议 ...

  6. HttpClient使用GET方式通过代理服务器读取页面的例子

    import java.io.BufferedReader;import java.io.InputStreamReader;import org.apache.http.HttpEntity;imp ...

  7. socket通信——通过Udp传输方式,将一段文字数据发送出去

    需求:通过Udp传输方式,将一段文字数据发送出去 定义一个Udp发送端 思路: 1.建立updsocket服务 2.提供数据,并将数据封装到数据包中. 3.通过socket服务的发送功能,将数据包发出 ...

  8. 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件

    [源码下载] 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  9. 使用httpClient调用接口获取响应数据

    转自:https://blog.csdn.net/shuaishuaidewo/article/details/81136088 import lombok.extern.slf4j.Slf4j; i ...

随机推荐

  1. get merge --no-ff和git merge区别、git fetch和git pull的区别

    get merge --no-ff和git merge区别 git merge -–no-ff可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge则不 ...

  2. SpringBoot 返回Json实体类属性大小写问题

    今天碰到的问题,当时找了半天为啥前台传参后台却接收不到,原来是返回的时候返回小写,但是前台依旧大写传参. 查了很多后发现其实是json返回的时候把首字母变小写了,也就是Spring Boot中Jack ...

  3. Dubbo学习摘录(零)

    节点角色说明: Provider:暴露服务的服务提供方: Consumer:调用远程服务的服务消费方: Registry:服务注册与发现的注册中心: Monitor: 统计服务的调用次数和调用时间: ...

  4. 监听EF执行的sql语句及状态

    1.监听EF执行sql的方式 db.Database.Log += c => Console.WriteLine($"sql:{c}"); SQL Server Profil ...

  5. z7z8记录

    http://www.ypppt.com/ ppt模板地址

  6. 浅谈对BFC的认识,以及用bfc解决浮动问题

    我们在前端的学习过程中常常会遇到BFC,用BFC来解决一些margin塌陷.margin合并清理浮动流的问题 那么问题来了,我们所说的BFC到底是个什么东西呢: 什么是BFC BFC(Block Fo ...

  7. js(es6)数组去重

    // 利用set.reduce.filter去重 // Set function getSetArr(arr) { return [...new Set(arr)] } console.log(get ...

  8. 行内块inline-block元素之间出现空白间隙原因及解决办法

    首先,来看下具体的问题,下面是用inline-block布局实现的两边固定宽度,中间自适应的html代码: 1 2 3 4 5 6 7 8 9 <section class="layo ...

  9. Java 之 函数式编程

    一.Lambda 的延迟执行 有些场景的代码执行后,结果不一定会被使用,从而造成性能浪费.而Lambda表达式是延迟执行的,这正好可以作为解决方案,提升性能 . 性能浪费的日志案例 注意:日志可以帮助 ...

  10. Qt 子线程更新Ui

    最近做练习,写一个Qt版的飞机大战,需要用子线程更新UI,发现Qt子线程不能更新Ui,否则程序会崩溃.在网上百度了下,说是需要在子线程自定义信号,然后在线程回调的run()函数里发射信号,主线程连接信 ...