본문 바로가기
Today I learned

Get은 헤더로만 데이터를 저장 할 수 있다. POST는 헤더 또는 body에 전달인자를 저장할 수 있다.

by soheemon 2019. 1. 15.

GET setAttribute 메서드 로 request에 Attribute를 저장 할 수 있다.

POST는 헤더는 물론 

body는 HttpsUrlConnetion객체에 OutputStream을 연결해서,

파라미터들을 byte 형식으로 써주는 형식으로 body에 데이터를 전송 가능하다.


con = (HttpsURLConnection) reqestUrl.openConnection();


...생략....


                     if(isBodyData == true){

                              DataOutputStream out = null;

                              try {

                                      out = new DataOutputStream(con.getOutputStream());

                                      out.writeBytes((String)param);

                                      out.flush();// 버퍼 비움. 전송!

                              } catch (IOException e) {

                                      e.printStackTrace();

                              } finally {

                                      closeOutStream(out);

                              }

                       }else {

                              HashMap<String, String> header = (HashMap<String, String>)param;

                           for (String key : header.keySet()){

                               con.setRequestProperty(key, header.get(key));

                           }

                       }

        }


댓글