🐳 Infra/System
CURL 사용 HTTP 메소드 별 테스트
terranbin
2025. 1. 29. 16:22
728x90
SMALL
최근에는 PostMan > HTTP Request 로 메소드별 API 테스트를 하나,
리눅스에서도 curl (Client URL) 명령어를 이용하여 확인을 하기도 한다
1. GET 메소드
- 설명: 서버로부터 데이터를 조회.
- 명령어:
curl -X GET https://sungbin-park.tistory.com/80
- 옵션 설명: -X GET은 HTTP GET 메소드를 사용하도록 지정. 생략해도 기본값은 GET.
2. POST 메소드
- 설명: 서버에 데이터를 생성하거나 전송.
- 명령어:
curl -X POST https://sungbin-park.tistory.com/80 -d "key1=value1&key2=value2"
- 옵션 설명:
- -d: POST 요청의 데이터(payload)를 지정.
- 데이터는 key=value 형식으로 작성하며, JSON 데이터를 보낼 경우:
curl -X POST https://sungbin-park.tistory.com/80 -H "Content-Type: application/json" -d '{"key1":"value1","key2":"value2"}'
3. PUT 메소드
- 설명: 서버의 리소스를 수정하거나 새롭게 저장.
- 명령어:
curl -X PUT https://sungbin-park.tistory.com/80/resource -d "key1=value1&key2=value2"
- 옵션 설명:
- PUT은 -d와 함께 서버에 데이터 업로드를 시뮬레이션.
- https://sungbin-park.tistory.com/resource는 수정할 리소스의 경로.
4. DELETE 메소드
- 설명: 서버의 리소스를 삭제.
- 명령어:
curl -X DELETE https://sungbin-park.tistory.com/80/resource
- 옵션 설명: DELETE 메소드를 사용하여 특정 리소스 삭제 요청.
5. HEAD 메소드
- 설명: 서버 응답 헤더만 조회.
- 명령어:
curl -X HEAD https://sungbin-park.tistory.com
- 옵션 설명: 서버의 응답 헤더만 반환하며 본문은 제외.
curl -X HEAD https://sungbin-park.tistory.com
6. PATCH 메소드
- 설명: 서버 리소스의 부분 업데이트.
- 명령어:
curl -X PATCH https://sungbin-park.tistory.com/resource -d "key1=value1"
- 옵션 설명: -d 옵션을 사용하여 업데이트할 데이터 전송.
- 결과
7. OPTIONS 메소드
- 설명: 특정 URL에서 지원하는 메소드 조회.
- 명령어:
curl -X OPTIONS https://sungbin-park.tistory.com
- 옵션 설명: OPTIONS 메소드는 서버가 해당 URL에서 지원하는 메소드 목록을 반환.
- 결과
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
8. TRACE 메소드
- 설명: 서버로 요청이 전달되는 과정을 추적.
- 명령어:
curl -X TRACE https://sungbin-park.tistory.com
- 실행 결과
<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>openresty</center>
</body>
</html>
이런 tistory 페이지는 보안이 있기에 GET Method 만 가능하다
LIST