Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 설치
- python 기초
- python 멀티프로세싱
- 명령어
- 기초
- 가상 환경
- 자바스크립트
- Anaconda
- 파이썬 학습 테스트
- Java
- EasyOCR
- easyocr 기존 모델 학습
- javascript
- python 학습
- python
- easyocr 기존 모델
- python multiprocessing
- conda
- 파이썬 기초
- python pool
- multiprocessing
- 기존 모델 학습
- 함수
- 자료형
- 리액트
- 파이썬
- python easyocr 학습
- 파이썬 pool
- react
- 파이썬 멀티프로세싱
Archives
- Today
- Total
귀찮아서가끔하는블로그
[JAVA] by pass 통신 본문
반응형
/**
* by pass 통신
*
* @param url, data, option(GET/POST)
* @return ResponseEntity<String> 성공여부
*/
public JSONObject byPass(String url, JSONObject jsonData, String option) {
Log.TraceLog("***************** BY PASS START*****************");
JSONObject responseJson = new JSONObject();
try {
// 연결할 url 생성
URL start_object = new URL(url);
Log.TraceLog("CONNECT URL :" + url);
// http 객체 생성
HttpURLConnection start_con = (HttpURLConnection) start_object.openConnection();
start_con.setDoOutput(true);
start_con.setDoInput(true);
// 설정 정보
start_con.setRequestProperty("Content-Type", "application/json");
start_con.setRequestProperty("Accept", "application/json");
start_con.setRequestMethod(option);
// data 전달
Log.TraceLog("REQUEST DATA : " + jsonData);
// 출력 부분
OutputStreamWriter wr = new OutputStreamWriter(start_con.getOutputStream());
wr.write(jsonData.toString());
wr.flush();
// 응답 받는 부분
StringBuilder start_sb = new StringBuilder();
int start_HttpResult = start_con.getResponseCode();
// 결과 성공일 경우 = HttpResult 200일 경우
if (start_HttpResult == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(start_con.getInputStream(), "utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
start_sb.append(line);
}
responseJson.put("data", start_sb);
responseJson.put("result", "SUCCESS");
br.close();
Log.TraceLog("***************** BY PASS SUCCESS *****************");
return responseJson;
} else {
// 그 외의 경우(실패)
Log.TraceLog("***************** BY PASS FAIL *****************");
responseJson.put("result", "FAIL");
return responseJson;
}
} catch (Exception e) {
Log.TraceLog("***************** BY PASS FAIL Exception *****************");
Log.TraceLog(e.toString());
responseJson.put("result", "EXCEPTION");
return responseJson;
}
}
반응형
'JAVA' 카테고리의 다른 글
[JAVA] 한글 -> 영어 변환 (0) | 2022.07.11 |
---|---|
[JAVA] Spring boot API 호출 샘플 만들기 (0) | 2022.07.05 |
[JAVA] request 데이터 파싱 (0) | 2022.05.10 |
[JAVA] 스트링 타입 데이터를 json형식으로 파싱하는 메소드 (0) | 2022.05.09 |
Comments