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. python3遍历选中文件夹下的文件【GUI编程】

    功能介绍 如标题 使用截图 1.第一步:运行python程序 2.第二步:点击按钮选中文件夹 3.运行结束: 1. 显示选中文件夹路径 2. 遍历打印文件夹内文件 代码 import os #程序功能 ...

  2. PHP中的字符串类型

    PHP支持两种类型的字符串,这些字符串用引号说明. 1.如果希望赋值一个字面意义的字符串,精确保存这个字符串的内容,应该用单引号标注,例如: $info='You are my $sunshine'; ...

  3. https://coderwall.com/p/7smjkq/multiple-ssh-keys-for-different-accounts-on-github-or-gitlab

    Multiple SSH keys for different accounts on Github or Gitlab SSH GIT GITLAB GITHUB Sometimes you nee ...

  4. 将电脑特定文件夹保存在U盘中

    为什么 各种网盘,借着国家扫黄的阶梯,纷纷取消自己的网盘的服务.但自己有一些不是很大,但又很重要的东西,比如说代码(虽然学的渣) 怎么做 再网上百度,有一些将U盘的文件偷偷拷到电脑的脚本,改一下复制文 ...

  5. CorelDRAW购物节福利开奖 | “剁手节”前的攻略来了,请查收!

    距离“剁手节” 还有不到两周的时间 相信一些线上.线下.微商.电商...都拿出了看家本领进行市场混战 一场没有硝烟的战争开始啦!! …… 当然,我也不例外 你们谁都别拦着,我要打广告了 让你变成了不折 ...

  6. parent() parents() parentsUntil()三者之间的对比

    $(document).ready(function(){ $("span").parent(); });只拿到span的父级标签 $(document).ready(functi ...

  7. Asp.net Core 源码-PagedList<T>

    using System.Collections.Generic; using System.Linq; using System; using System.Linq.Expressions; us ...

  8. IT级别

    IT领袖:年入过亿(例如任正非.马化腾.李彦宏.丁磊.马云等,包括期权股票以及投资理财等收入.) IT大哥:年入千万(级别次于以上几位大佬的公司老板,不缺钱,普遍对上一条里的人物羡慕嫉妒恨.) IT精 ...

  9. U盘启动盘安装Mac OS

    1.下载macOS High Sierra正式版 http://www.pc6.com/mac/gj_715_1.htm http://www.pc6.com/mac/518996.html 下载ma ...

  10. 【JavaScript框架封装】数据类型检测模块功能封装

    数据类型检测封装后的最终模块代码如下: /*数据类型检验*/ xframe.extend(xframe, { // 鸭子类型(duck typing)如果它走起路来像鸭子,叫起来也是鸭子,那么它就是鸭 ...