package com.cn.baidu;
import java.io.bufferedreader;
import java.io.ioexception;
import java.io.inputstream;
import java.io.inputstreamreader;
import java.util.arraylist;
import java.util.list;
import org.apache.commons.httpclient.defaulthttpmethodretryhandler;
import org.apache.commons.httpclient.header;
import org.apache.commons.httpclient.httpclient;
import org.apache.commons.httpclient.httpexception;
import org.apache.commons.httpclient.httpstatus;
import org.apache.commons.httpclient.methods.getmethod;
import org.apache.commons.httpclient.params.httpmethodparams;
public class holiday
{
/**
* @param urlall :请求接口
* @param httparg :参数
* @return 返回结果
*/
public static string request(string httparg)
{
string httpurl = "http://www.easybots.cn/api/holiday.php";
// string httpurl = "http://apis.baidu.com/xiaogg/holiday/holiday";
httpclient httpclient = new httpclient();
getmethod method = new getmethod(httpurl+"?"+httparg);
string response = "";
try
{
// 需要添加的header数据
list
header header = new header();
header.setname("apikey");
header.setvalue("7bd4e99adcc28e337cea79191fef87fc");
headers.add(header);
httpclient.gethostconfiguration().getparams().setparameter("http.default-headers", headers);
method.getparams().setparameter(httpmethodparams.retry_handler, new defaulthttpmethodretryhandler());
int statuscode = httpclient.executemethod(method);
if (statuscode == httpstatus.sc_ok)
{
// 获取到的回执信息
inputstream resstream = method.getresponsebodyasstream();
bufferedreader br = new bufferedreader(new inputstreamreader(resstream));
stringbuffer resbuffer = new stringbuffer();
string restemp = "";
while ((restemp = br.readline()) != null)
{
resbuffer.append(restemp);
}
response = resbuffer.tostring();
}
}
catch (httpexception e)
{
e.printstacktrace();
}
catch (ioexception e)
{
e.printstacktrace();
}
finally
{
method.releaseconnection();
}
return response;
}
public static void main(string[] args)
{
// 工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
string httparg = "d="+"2016-11-20".replaceall("-", "");
string jsonresult = request(httparg);
system.out.println(jsonresult);
}
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号