관리 메뉴

웹개발 블로그

[HTML Form 데이터 전송] application/x-www-form-urlencoded 과 multipart/form-data 차이 본문

◆SPRING/정리

[HTML Form 데이터 전송] application/x-www-form-urlencoded 과 multipart/form-data 차이

쿠키린 2023. 4. 4. 10:19
 Content-Type: application/x-www-form-urlencoded 사용
• form의 내용을 메시지 바디를 통해서 전송(key=value, 쿼리 파라미터 형식)
• 전송 데이터를 url encoding 처리
• 예) abc김 -> abc%EA%B9%80

파일을 업로드 하려면 파일은 문자가 아닌 바이너리 데이터를 전송해야한다.

그리고 폼에다가는 제목 그리고 첨부파일 등록하는 것 처럼 폼을 전송 시에는

파일만 보내지 않는다는 점이다.

 

그래서⬇️

Content-Type: multipart/form-data
• 파일 업로드 같은 바이너리 데이터 전송시 사용
• 다른 종류의 여러 파일과 폼의 내용 함께 전송 가능(그래서 이름이 multipart)
<form action="/save" method="post" enctype="multipart/form-data">
 <input type="text" name="username" />
 <input type="text" name="age" />
 <input type="file" name="file1" />
 <button type="submit">전송</button>
</form>

enctype="multipart/form-data" <-- form 태그에다가 넣어준다.