How to send network requests and data transmission in Linux

The curl command is used for network requests and data transfer in the terminal.

  1. Send a GET request:

    curl [URL]
    

    Using the curl command plus the URL to be requested, you can send a GET request and display the response results.

  2. Send POST request:

    curl -X POST -d "参数" [URL]
    

    Use -X POSToptions to specify the request method as POST, and use -doptions to specify the parameters of the POST request.

  3. Set request headers:

    curl -H "头部信息" [URL]
    

    Use -Hoptions to set custom request headers, -H "Content-Type: application/json"e.g.

  4. Save response to file:

    curl -o [保存的文件名] [URL]
    

    Use -othe option followed by the saved file name to save the response to a specified file.

  5. Follow the redirect:

    curl -L [URL]
    

    Using -Loptions, you can have curl automatically follow redirects returned by the server.

  6. Use a proxy:

    curl -x [代理地址:端口号] [URL]
    

    Use -xoptions to set up a proxy server for requests.

  7. Resumable upload:

    curl -C - -T [本地文件路径] [URL]
    

    Using -C - -Tthe option, you can resume uploading files after a breakpoint, and only upload the new part of the file.

  8. Download a file and show progress:

    curl -O [URL]
    

    Using -Othe option, you can download the file to the current directory and display the download progress in the terminal.

Guess you like

Origin blog.csdn.net/drhnb/article/details/132052017