Linux

[Linux] Curl(Client url) 명령어에 대해 알아보자

SeungbeomKim 2024. 6. 4. 18:28
반응형

curl은 다양한 통신 프로토콜을 이용하여 데이터를 전송하기 위한 라이브러리와 명령줄 도구를 제공하는 컴퓨터 소프트웨어 프로젝트입니다. (https://ko.wikipedia.org/wiki/CURL)


즉, curl은 프로토콜을 이용하여 url 구문을 입력해 인터넷에서 파일을 포함한 데이터를 가져오거나 보내는 명령줄 도구라고 보시면 됩니다. 수많은 프로토콜을 지원하기에 다양한 데이터를 주고받기에 용이한 도구입니다. 

 

  1. 웹 페이지 요청 및 다운로드 (HTTP): URL을 통해 웹 페이지 내용을 가져올 수 있습니다.
  2. 파일 업로드 및 다운로드: FTP, SFTP를 통해 파일을 업로드하거나 다운로드할 수 있습니다.
  3. API: RestAPI나 기타 웹 서비스를 호출하여 데이터를 주고받을 수 있습니다.

  

Curl -V 

  • Curl Version, Release Date, 지원하는 Protocols 등을 보여줍니다.

 

Curl --help all

  • Curl 명령어 옵션을 모두 확인할 수 있는 명령어입니다.
  • curl [options] <url>에서 옵션과 옵션에 대한 설명을 상세히 보여줍니다.
  • 대표적인 옵션 
    • -k, --insecure           Allow insecure server connections
    • -d, --data <data>        HTTP POST data
    • -H, --header <header/@file> Pass custom header(s) to server
    • -X, --request <method>   Specify request method to use
    • -v, --verbose            Make the operation more talkative
    • -V, --version            Show version number and quit
    • -s, --silent             Silent mode (Only HTTP Response Code)
    • -L, --location           Follow redirects (HTTP 301, 302 Redirect -> default : 50)
    • -u, --user <user:password> Server user and password
    • -I, --head               Show document info only (header)
    • -i, --include            Include protocol response headers in the output (header + body)

 

curl 사용 예시

curl -XGET -k -s -uapi:api123 'https://192.168.229.182:8443/api/v2/devices' | json
{
  "header": {
    "result_code": 0,
    "result_message": null,
    "successful": true
  },
  "results": [],
  "result": [
    {
      "device_id": 3,
      "organization": "조직-1",
      "network": "A",
      "name": "CS3856G",
      "oper_status": 4,
      "type": 2
    },
    {
      "device_id": 4,
      "organization": "조직-1",
      "network": "A",
      "name": "3856",
      "oper_status": 4,
      "type": 2
    },
    {
      "device_id": 5,
      "organization": "조직-1",
      "network": "A",
      "name": "CS3852GXE",
      "oper_status": 4,
      "type": 2
    },
    {
      "device_id": 6,
      "organization": "조직-1",
      "network": "A",
      "name": "CS3856XQ",
      "oper_status": 4,
      "type": 2
    },
    {
      "device_id": 7,
      "organization": "조직-1",
      "network": "A",
      "name": "3856XQ",
      "oper_status": 4,
      "type": 2
    },
    {
      "device_id": 9,
      "organization": "조직-2",
      "network": "A",
      "name": "CS2710G",
      "oper_status": 4,
      "type": 0
    },
  ]
}

 

간단하게 curl 명령어에 대해 알아보았습니다. 

반응형