Skip to content

CURL

cURL is a computer software project providing a library and command-line tool for transferring data using various protocols. The cURL project produces two products, libcurl and cURL. It was first released in 1997.

다양한 프로토콜을 사용한 데이터 전송을 지원하는 명령어 기반의 프로그램과 C API 라이브러리를 제공한다.

Categories

  • libcurl: C API에 관련된 내용 정리.

Examples

너무 많아서 별도 페이지로 분할.

대체제

자신의 글로벌 IP 확인

글로벌 IP를 확인해 주는 사이트에 방문하자:

  • curl ifconfig.me
  • curl ident.me
  • curl ifconfig.me
  • curl icanhazip.com
  • curl ipecho.net/plain
  • curl ipv4.icanhazip.com

Options

-f, --fail
HTTP 상태코드가 200이 아닐 경우 Exit Code에 에러를 전파한다. 명령행 스크립트를 작성할 때 필요하다.
--connect-timeout
Maximum time in seconds that you allow the connection to the server to take.
-m, --max-time
Maximum time in seconds that you allow the whole operation to take.
-s, --silent
Silent or quiet mode.
So if you don't want any output use: curl -s 'http://example.com' > /dev/null
-L, --location
301 Moved Permanently 에러가 발생되었을 경우 헤더의 Location 정보를 참조하여 수정된 주소로 이동한다.
-o [FILE]
다운받을 파일이름을 지정한다.
curl -o index.htmlhttp://www.netscape.com/
-O
웹페이지의 파일이름을 사용하여 다운받는다.
curl -Ohttp://www.netscape.com/index.html
-u/--user [username][:passwd]
인증을 위한 ID와 PASSWORD.
-e [Referrer URL]
리퍼러 (referer)를 설정한다. (referrer)
--max-filesize [size]
다운받을 파일 크기 제한.
-T/--upload-file [FILE]
Transfer file to remote site.
-s/--silent
Silent mode. Don't output anything.
-S/--show-error
Show error. With -s, make curl show errors when they occur.
-m/--max-time [seconds]
Maximum time allowed for the transfer.
--connect-timeout [seconds]
Maximum time allowed for connection.
--ftp-create-dirs
Create the remote dirs if not present (F).
--verbose, --trace,, --trace-ascii
프로토콜 디버깅. HTTP 데이터 통신 과정에 대한 상세정보를 얻을 수 있다. verbose로 불충분하다면 trace-ascii를 사용하자.
-k, --insecure
안전하지 않는 서버도 강제로 연결. 서버의 인증서에 올바른 이름이 포함되어 있는지 확인하여 서버 연결을 확인하고 인증서 저장소를 사용하여 성공적으로 확인합니다.

Error codes

CURLE_OK (0)
All fine. Proceed as usual.
CURLE_OPERATION_TIMEDOUT (28)
Operation timeout. The specified time-out period was reached according to the conditions.
CURLM_ADDED_ALREADY (7)
An easy handle already added to a multi handle was attempted to get added a second time. (Added in 7.32.1)
CURLE_GOT_NOTHING (52)
Nothing was returned from the server, and under the circumstances, getting nothing is considered an error.

인증기관 목록 추가

curl 을 실행시 -v 옵션으로 CA 목록을 어디에서 가져오는지 위치를 확인한다.

$ curl -v  https://google.com
* About to connect() to google.com port 443 (#0)
*   Trying 74.125.128.139... connected
* Connected to google.com (74.125.128.139) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
  • Ubuntu/etc/ssl/certs/ca-certificates.crt 또는 /etc/ssl/certs 디렉터리에서 CA 목록 로딩
  • RHEL/CentOS 는 아래와 같이 /etc/pki/tls/certs/ca-bundle.crt에서 CA 목록을 로딩함
  • Mac OSX는 /etc/ssl/cert.pem에서 CA 목록을 로딩함

인증서 추출 방법은 OpenSSL 항목 참조.

Bash 쉘 또는 PowerShell 에서 다운받은 스크립트를 파일로 저장하지 않고 바로 실행

k3s의 샘플 예제 참조:

curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644

축약하면 다음과 같다:

curl -sfL https://raw.githubusercontent.com/your/bash/script.sh | bash

참고로 PowerShell에서 위와 비슷한 명령을 사용하고 싶다면:

powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"

curl이 없을 경우 대체 방법

See also

  • URI
  • URL
  • URN
  • wget
  • Fiddler
  • WireShark
  • ciao - 간단한 서버 HTTP 모니터링 도구
  • aria2 - aria2 is a lightweight multi-protocol & multi-source command-line download utility.
  • crul - 모든 웹페이지 또는 API를 무료로 쿼리해주는 도구
  • resty - 명령행
  • HTTPie (httpie) - 명령행
  • Vim REST Console - vim 플러그인
  • Posting - 터미널용 HTTP API 클라이언트
  • Pipet - 온라인에서 데이터를 스크래핑/추출하는 CLI 도구
  • ArchiveBox - ArchiveBox는 인터넷 아카이브를 자체 호스팅

Favorite site

References


  1. Document page: Curl.haxx.se.zip