HttpURLConnection con;
String url;
HttpReq() {
}
HttpReq(String url) throws IOException {
this.url = url;
URL myurl = new URL(url);
con = (HttpURLConnection) myurl.openConnection();
}
void closeServer() {
con.disconnect();
}
public StringBuilder get() throws IOException {
StringBuilder content;
con.setRequestMethod("GET");
try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String line;
content = new StringBuilder();
while ((line = in.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
}
System.out.println(content.toString());
return content;
}
public StringBuilder post() throws IOException {
String urlParameters = "name=Jack&occupation=programmer";
StringBuilder content;
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "Java client");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
wr.write(postData);
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String line;
content = new StringBuilder();
while ((line = in.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
}
System.out.println(content.toString());
return content;
}
2018년 10월 22일 월요일
flutter 기본 개념 1
Scaffold - 화면 뼈대 역할 - 기본적으로 AppBar body floatingActionButton 같은걸 배치해줌 return Scaffold ( appBar : AppBar ( title : const Text ...
-
Introduction Dynamic Programming (DP) is a fundamental concept in computer science and algorithmic problem-solving. It's a technique tha...
-
Scaffold - 화면 뼈대 역할 - 기본적으로 AppBar body floatingActionButton 같은걸 배치해줌 return Scaffold ( appBar : AppBar ( title : const Text ...
-
도커 상태 확인 현재 실행중인 프로세스 docker ps 실행 했던 프로세스 docker ps -a 설치된 이미지 목록 docker images 도커 이미지 관리 이미지 받아오기 docker pull image이름 이...