티스토리 뷰
package navermap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class NowDateFromServer {
public final static String DUE_STR="20230204";
public final static String USER_ID="ksd";
public final static String GET_SET_DATE_URL="http://localhost/navermap/getSettingDate.php";
public final static String GET_DATE_URL="http://localhost/navermap/getNowDate.php";
public final static String LOG_URL="http://localhost/navermap/insertLog.php";
public static boolean isBefore() throws Exception {
boolean rst=false;
//String nowStr="20230105";
URL url = new URL(GET_DATE_URL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
// optional default is GET
con.setRequestProperty("User-Agent", "Mozilla/5.0");
// add request header
int responseCode = con.getResponseCode();
System.out.println("HTTP 응답 코드 : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
} in.close(); // print result
System.out.println("HTTP body : " + response.toString());
JSONParser jsonParser = new JSONParser();
String jsonInfo=response.toString();
System.out.println("jsonInfo="+jsonInfo);
JSONObject jsonObject = (JSONObject) jsonParser.parse(jsonInfo);
System.out.println("jsonObject="+jsonObject);
String nowStr = (String) jsonObject.get("nowDate");
System.out.println("nowStr="+nowStr);
//String dueStr="20230204";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate nowDate=LocalDate.parse(nowStr, formatter);
LocalDate dueDate=LocalDate.parse(DUE_STR, formatter);
System.out.println(nowDate);
System.out.println(dueDate);
rst=nowDate.isBefore(dueDate);
//System.out.println(rst);
return rst;
}
public static boolean isBeforeByUserId(String user_id) throws Exception {
boolean rst=false;
//String nowStr="20230105";
String settingUrl = GET_SET_DATE_URL+"?user_id="+user_id;
URL url = new URL(settingUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
// optional default is GET
con.setRequestProperty("User-Agent", "Mozilla/5.0");
// add request header
int responseCode = con.getResponseCode();
System.out.println("HTTP 응답 코드 : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
} in.close(); // print result
System.out.println("HTTP body : " + response.toString());
JSONParser jsonParser = new JSONParser();
String jsonInfo=response.toString();
System.out.println("jsonInfo="+jsonInfo);
JSONObject jsonObject = (JSONObject) jsonParser.parse(jsonInfo);
System.out.println("jsonObject="+jsonObject);
String nowStr = (String) jsonObject.get("nowDate");
System.out.println("nowStr="+nowStr);
//String dueStr="20230204";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate nowDate=LocalDate.parse(nowStr, formatter);
LocalDate dueDate=LocalDate.parse(DUE_STR, formatter);
System.out.println(nowDate);
System.out.println(dueDate);
rst=nowDate.isBefore(dueDate);
//System.out.println(rst);
return rst;
}
public static void log() throws Exception {
String logUrl=LOG_URL+"?user_id="+USER_ID;
System.out.println("logUrl="+logUrl);
URL url = new URL(logUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
int responseCode = con.getResponseCode();
System.out.println("HTTP 응답 코드 : " + responseCode);
}
public static void main(String[] args) throws Exception {
boolean b = NowDateFromServer.isBefore();
boolean b2 = NowDateFromServer.isBeforeByUserId("aa");
System.out.println("isBefore="+b);
System.out.println("isBeforeByUserId="+b2);
log();
}
}
'자바(Java)' 카테고리의 다른 글
Exception in thread "main" javax.net.ssl.SSLHandshakeException: No subject alter (0) | 2023.02.17 |
---|---|
자바 마리아 db 소수점 심각: java.lang.NumberFormatException: For input string: " (0) | 2023.01.19 |
자바 현재날짜 이전날짜 문자열로 비교 (0) | 2023.01.05 |
자바 날짜 현재월 이전달 최근 6개월 (0) | 2022.12.15 |
404 File Not Found 페이지를 찾을 수 없습니다 (0) | 2022.12.12 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- XE3
- 자바 smtp
- 자바
- ocjap
- XE
- JDBC
- EC
- Python
- KG
- C
- 파싱
- MySQL
- 오라클
- 파이썬
- 플러터
- php
- 인포믹스
- proc
- xe애드온
- 이클립스
- 스크래핑
- xe addon
- C언어
- 프로씨
- 라이믹스
- ocajp
- 문자열
- webix
- esql
- 포인터
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함