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 |
Tags
- dkms
- nouveau
- Spring
- docker
- Python
- 비디오미리보기
- nfs mount
- Linux
- 딥스트림
- 정처기
- yolov7
- 도커 컨테이너
- 주피터 노트북
- IOU
- 딥러닝
- 리눅스
- 스프링
- 타오툴킷
- 파이썬
- tao_toolkit
- C
- 알고리즘
- mAP@.5
- deepstream
- pyMySQL
- 네트워크
- SQLD
- C++
- 도커
- 백준
Archives
- Today
- Total
한 번만 더 해보자
[Spring] 서버 연결하기 본문
public String connectServer(HttpServletRequest request) {
URL url;
try {
url = new URL("서버 주소");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setConnectTimeout(5000); // 타임아웃 설정
String json = "{\"json\":\"json\"}";
OutputStream os = conn.getOutputStream();
os.write(json.getBytes());
os.flush();
//서버연결 실패시
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
} catch (IOException e) {
e.printStackTrace();
return "serverError";
}
return "success";
}반응형