首頁  >  文章  >  Java  >  取得當天是否假日

取得當天是否假日

巴扎黑
巴扎黑原創
2016-12-03 11:56:432744瀏覽

打包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

; headers = new ArrayList
(); 
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); 


}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn