inblog logo
|
parangdajavous
    Spring Boot

    [Spring Boot] 9. HTTP Protocol

    김미숙's avatar
    김미숙
    Apr 02, 2025
    [Spring Boot] 9. HTTP Protocol
    welcome 요청 -> index.html
    method -> get post put delete
    post와 put은 body 데이터가 있다. body 데이터가 있으면, 반드시 Content-Type으로 body 데이터를 설명해야 한다.
    mime 타입 text/plain text/html x-www-form-urlcoded application/json
    HTTP 상태코드 10x -> 기다려 나 좀 바빠 20x -> 성공 30x -> Redirection // 요청이 두번 일어남. 상태코드와 Location 키값 필요 40x -> 너(클라이언트) 요청 잘못했는데? 50x -> 서버 에러 (DB에 모아놔야함)
    Redirection
    ➡ Status 코드가 30x이면 Location 키값을 확인하고 이동한다
    @Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doDelete"); resp.setStatus(302); // 해당 로케이션으로 이동하라 resp.setHeader("Location", "http://www.naver.com"); }
    Location 만 줬을때
    ➡ value에 "http://www.naver.com" 가 들어감
    notion image
    Status(302) 상태 코드를 주면?
    ➡ Redirection 되서 Location 키 값인 "http://www.naver.com”로 이동하게 됨
    notion image
     
    Cookie -> 서버가 클라이언트한테 응답할 때 Set-Cookie : key=value;key=value 클라이언트는 저 값을 브라우저에 저장한다 클라이언트는 요청 시마다 쿠키를 가지고 서버로 요청한다 Cookie : key=value;key=value
    Cookie
    @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPut"); Cookie cookie = new Cookie("c03", "apple"); Cookie cookie2 = new Cookie("c03", "banana"); resp.addCookie(cookie); // 기존에 있던 쿠키 건들지 않고 추가 resp.addCookie(cookie2); // Set-Cookie : c03=apple;c03=banana }
    notion image
    User-Agent -> OS이름, 프로그램명
    Share article

    parangdajavous

    RSS·Powered by Inblog