하고재비
[JAVA Network]http 데이터 전송방식 - get / post, post example 본문
get - url 에 포함시켜 데이터 전송 (데이터를 읽어올때)
단순한 페이지에 사용하는 방식
url '?' 뒤의 인자에 데이터를 추가시켜 전송, 간단한 페이지에 사용
데이터가 노출되어 보안성이 떨어짐
데이터 길이의 제한 - 데이터 전송 용량 적음
example
http://httpbin.org/get?%2FName%2FGender=male
post - http body 부분에 데이터를 숨겨서 보내는 방식 (서버의 데이터를 변경 할때)
url에 포함시키지 않아 보안성이 좋아보이긴 하지만 안전하진 않음
(http response MSG 분석으로 데이터 찾아올수 있음)
많은양의 데이터 전송용량
post example
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
//make url
URL url = new URL("http://httpbin.org/post");
// make urlconn
URLConnection uc = url.openConnection();
//setoutput , 출력모드
uc.setDoOutput(true);
//make output stream
OutputStreamWriter ow = new OutputStreamWriter(uc.getOutputStream());
// setup data and output
ow.write("Name=DeadDE & Number=11");
ow.close();
// result
BufferedReader bf = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String str = "";
while((str = bf.readLine()) != null){
System.out.println(str);
}
bf.close();
}
코드 결과
{
"args": {},
"data": "",
"files": {},
"form": {
" Number": "11",
"Name": "DeadDE "
},
"headers": {
"Accept": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
"Content-Length": "23",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Java/1.8.0_221",
"X-Amzn-Trace-Id": "Root=1-60be48e3-0df057fd52d92b93380c27f4"
},
"json": null,
"origin": "119.85.107.89",
"url": "http://httpbin.org/post"
}