1.pom.xml

    <properties>
<slf4j.version>1.7.21</slf4j.version>
<okhttp.version>3.4.2</okhttp.version>
<httpclient.version>4.5.2</httpclient.version>
<logback.version>1.1.7</logback.version>
</properties> <dependencies> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.21</version>
</dependency> <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>

2. 代码

    public void sendGet(String url){

        CloseableHttpClient httpclient = HttpClients.createDefault();

        RequestConfig requestConfig = RequestConfig
.custom()
.setSocketTimeout(1000*60*60*5)
.setConnectTimeout(1000*60*60*5)
.build(); HttpGet httpget = new HttpGet(url);
httpget.setConfig(requestConfig); try {
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
logger.info("response is {}" ,response);
logger.info("entity is {}" ,entity);
logger.info("result is {}" ,EntityUtils.toString(entity));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//response.close();
} }

3.测试

    public static void main(String[] args) throws InterruptedException {
Sample sample=new Sample();
Calendar start=Calendar.getInstance();
start.set(2017, 7, 23); Calendar end=Calendar.getInstance();
end.set(2017, 7, 24);
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd"); while(true){
String startDate=formatter.format(start.getTime());
start.add(Calendar.DAY_OF_MONTH, 1);
String endDate=formatter.format(start.getTime());
String url="http://test.test.com/daily/getDailyAction?startDate="+startDate
+"&endDate="+endDate;
if(start.after(end)){
break;
}else{
sample.sendGet(url);
Thread.sleep(1000*60*2);
}
} }

httpclient定时请求实例的更多相关文章

  1. HttpClient post 请求实例

    所需jar包: commons-codec-1.3.jar commons-httpclient-3.0.jar commons-logging-1.1.1.jar /** * */ package ...

  2. HttpClient Get请求实例

    Httpclient是我们平时中用的比较多的,但是一般用的时候都是去网上百度一下,把demo直接拿过来改一下用就行了,接下来我们来看他的一些具体的用法.Apache HttpComponents™项目 ...

  3. httpclient post请求实例(自己写的)

    package com.gop.gplus.trade.common.utils; import org.apache.commons.httpclient.HttpClient;import org ...

  4. java HttpClient POST请求

    一个简单的HttpClient POST 请求实例 package com.httpclientget; import java.awt.List; import java.util.ArrayLis ...

  5. HttpClient模拟客户端请求实例

    HttpClient Get请求: /// <summary>        /// Get请求模拟        /// </summary>        /// < ...

  6. Java HttpClient伪造请求之简易封装满足HTTP以及HTTPS请求

    HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...

  7. 使用HttpClient发送请求接收响应

    1.一般需要如下几步:(1) 创建HttpClient对象.(2)创建请求方法的实例,并指定请求URL.如果需要发送GET请求,创建HttpGet对象:如果需要发送POST请求,创建HttpPost对 ...

  8. java HttpClient GET请求

    HttpClient GET请求小实例,先简单记录下. package com.httpclientget; import java.io.IOException; import org.apache ...

  9. .NetCore HttpClient发送请求的时候为什么自动带上了一个RequestId头部?

    奇怪的问题 最近在公司有个系统需要调用第三方的一个webservice.本来调用一个下很简单的事情,使用HttpClient构造一个SOAP请求发送出去拿到XML解析就是了. 可奇怪的是我们的请求在运 ...

随机推荐

  1. 对比JavaScript的入口函数和jQuery的入口函数

    JavaScript的入口函数要等到页面中所有的资源(包括图片.文件)加载完成才开始执行. jQuery的入口函数只会等待文档数加载完成就开始执行,并不会等待图片.文件的加载.

  2. Qt:&OpenCV—Q图像处理基本操作(Code)

    原文链接:http://www.cnblogs.com/emouse/archive/2013/03/31/2991333.html 作者写作一系列:http://www.cnblogs.com/em ...

  3. 实验7 OpenGL光照

    一.实验目的: 了解掌握OpenGL程序的光照与材质,能正确使用光源与材质函数设置所需的绘制效果. 二.实验内容: (1)下载并运行Nate Robin教学程序包中的lightmaterial程序,试 ...

  4. day27-2 pandas模块

    目录 pandas Series(了解) DataFrame 内置方法 处理缺失值 合并数据 取值 把表格传入excel文件中 把表格从excel中取出来 高级(了解) pandas 处理表格等文件/ ...

  5. pip是用代理

    内网访问外网时,需要通过vpn访问,但是pip貌似不能是用vpn访问外网.直接度娘: windows下: set http_proxy=http://代理服务器:端口 不行可以试试下面的: set h ...

  6. kali2018.2安装配置OpenVAS-9及错误处置

    1 配置环境 1)虚拟机环境:VMware® Workstation 14 Pro(版本号:14.1.2 build-8497320),如图1. 图1 虚拟机版本信息 2)kali镜像 Kali201 ...

  7. C语言求大数的阶乘

    我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,该如何计算? 当一个数很大时,利用平常的方法是求不出来它的阶乘的,因为数据超出了范围.因此我们要用数组来求一个大数的阶乘,用数组的每位表示结果的 ...

  8. 把SQLAlchemy查询对象转换成字典/json使用(分开)

    注:针对的是查询出来的是单条对象 多个对象的话可以使用for循环遍历查询出来的对象列表,也可以使用下面的方法 1.config.py文件 #!/usr/bin/env python #-*- codi ...

  9. Spring 使用外部属性文件配置

    1.Spring提供了一个PropertyPlaceholderConfigurer的BeanFactory后置处理器,这个处理器允许用户将Bean的配置的部分内容 移到属性文件中.可以在Bean配置 ...

  10. 搞定PHP面试 - 函数知识点整理

    一.函数的定义 1. 函数的命名规则 函数名可以包含字母.数字.下划线,不能以数字开头. function Func_1(){ } //合法 function func1(){ } //合法 func ...