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 |
Tags
- 스프링
- Servlet
- spring
- java
- Spring Boot
- 알고리즘
- Greedy
- 스프링 핵심 원리
- jpa
- SpringBoot
- 김영한
- 그리디
- kotlin
- Exception
- JPQL
- QueryDSL
- AOP
- 인프런
- transaction
- db
- Android
- 자바
- pointcut
- Proxy
- springdatajpa
- JDBC
- Thymeleaf
- 스프링 핵심 기능
- http
- 백준
Archives
- Today
- Total
개발자되기 프로젝트
HTTP 요청 데이터 - API 메시지 바디 - 단순 텍스트 본문
1. message body에 직접 데이터 담기
- HTTP API에서 주로 사용, JSON, XML, TEXT
- 데이터 형식은 주로 JSON 사용
- POST, PUT, PATCH
2. HTTP 메시지 바디의 데이터 읽는 방법
- InputStream을 사용
- message body의 바이트 코드 얻음.
- StreamUtils.copyToString(Stream, 인코딩) 을 통해 STring으로 변환.
@WebServlet(name = "RequestBodyStringServlet", urlPatterns = "/request-body-string")
public class RequestBodyStringServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//메세지 바디 바이트코드 얻음
ServletInputStream inputStream = request.getInputStream();
//messageBody꺼내기
String messageBody = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
System.out.println("messageBody = " + messageBody);
response.getWriter().write("ok~");
}
}
messageBody = hello~
3. GitHub : 210908 MessageBody, text
GitHub - bsh6463/MVC1
Contribute to bsh6463/MVC1 development by creating an account on GitHub.
github.com
'인프런 > [인프런] 스프링 MVC 1' 카테고리의 다른 글
HttpServletResponse - 기본 사용법 (0) | 2021.09.08 |
---|---|
HTTP 요청 데이터 - API 메시지 바디 - JSON (0) | 2021.09.08 |
HTTP 요청 데이터 - POST HTML Form (0) | 2021.09.08 |
HTTP 요청 데이터 - GET 쿼리 파라미터 (0) | 2021.09.08 |
HTTP 요청 데이터 (0) | 2021.09.08 |
Comments