303 See Other는 응답이 다른 URL에 있으며, 그 URL을 반드시 GET으로 가져오라고 지시합니다. 원래 요청이 POST였더라도 리다이렉트된 요청은 GET으로 바뀌는 것이 명세상 보장됩니다.
이 덕분에 POST-리다이렉트-GET(PRG) 패턴의 표준 도구로 쓰입니다. 폼 제출 후 결과 페이지로 보내면, 사용자가 새로고침해도 POST가 재전송되지 않아 중복 주문·중복 등록을 막을 수 있습니다.
POST /orders HTTP/1.1
Host: shop.example.com
Content-Type: application/x-www-form-urlencoded
item=book&qty=1HTTP/1.1 303 See Other
Location: /orders/5821
Content-Length: 0app.post('/orders', (req, res) => {
const id = createOrder(req.body);
res.redirect(303, `/orders/${id}`); // browser does GET /orders/:id
});@app.post('/orders')
def create_order():
oid = create(request.form)
return redirect(f'/orders/{oid}', code=303)