取得當天是否假日
Dec 03, 2016 am 11:56 AM打包com.cn.baidu;
導入java.io.BufferedReader;
導入java.io.IOException;
導入java.io.InputStream;
導入java.io.InputStreamReader; 導入java.util.List;
導入org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
導入org.apache.commons.httpclient.Header; Clorg.apache.commons.httpcliclient.HttCl. commons.httpclient.HttpException;
導入org.apache.commons.httpclient.HttpStatus;
導入org.apache.commons.httpclient.methods.GetMethod;
org.apache.commons.httpclient.methods.GetMethod;
.假期
{
/**
* @param urlAll :請求介面
* @param httpArg :參數
* @return 回傳結果
*/
public static String request(String httpArg)
{
String httpUrl = "http://www.easybots.cn/api/holiday.php";
// = "http://apis.baidu.com/xiaogg/holiday/holiday";
HttpClient httpClient = new HttpClient();
GetMethod 方法= new GetMethod(httpUrl+"?"+httpArg);
字串回應= "" ;
嘗試
{
//需要加入標題資料
List
Header header = new Header();
header.setName("apikey"); setValue("7bd4e99adcc28e337cea79191fef87fc");
headers.add(header);
httpClient.getHostConfiguration().getParams().setParameter("httpClient.getHostConfiguration().getParams().setParameter("httpClient.m." ams. RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_OK)
{ StreamStreamStreamStream 獲取到的資訊/發送資訊).
BufferedReader br = new BufferedReader(new InputStreamReader(resStream));
StringBuffer resBuffer = new StringBuffer();
String resTemp = "";
while ((resTemp = br.readLine() ! append(resTemp);
}
response = resBuffer.toString();
}
}
catch (HttpException e)
{
e.printStack (HttpException e)
{
e.printStack (HttpException e)
{
e.printStack (Htt); e.printStackTrace( );
}
終於
{
method.releaseConnection();
}
回傳回應;
}
public static v.結果為1,假日回覆結果為2
String httpArg = "d="+"2016 -11-20".replaceAll("-", "");
String jsonResult = request(httpArg);
System.out. println(jsonResult);
}
}

熱門文章

熱門文章

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

2025年的前4個JavaScript框架:React,Angular,Vue,Svelte

如何使用咖啡因或Guava Cache等庫在Java應用程序中實現多層緩存?

Spring Boot Snakeyaml 2.0 CVE-2022-1471問題已修復

如何將JPA(Java持久性API)用於具有高級功能(例如緩存和懶惰加載)的對象相關映射?

如何將Maven或Gradle用於高級Java項目管理,構建自動化和依賴性解決方案?
