cURL User Guide
cURL is a command-line tool and library for transferring data. It supports various protocols including HTTP, HTTPS, FTP, and more. cURL is particularly useful in web development for performing HTTP requests, file downloads, and API calls. ServBay comes with cURL pre-installed, and this article will provide a detailed introduction to the installation, configuration, and usage of cURL.
Table of Contents
Installation and Configuration
Installation
ServBay comes with cURL pre-installed, so no additional installation is required.
Configuration
No configuration is required by default.
Basic Usage
cURL offers a wealth of command-line options for various data transfer tasks. Here are some basic usage examples:
Sending an HTTP GET Request
curl -X GET https://api.example.com/data
Sending an HTTP POST Request
curl -X POST -d "param1=value1¶m2=value2" https://api.example.com/data
Downloading a File
curl -O https://example.com/file.zip
Uploading a File
curl -X POST -F "file=@/path/to/file" https://api.example.com/upload
Advanced Usage
Setting HTTP Headers
curl -H "Content-Type: application/json" -H "Authorization: Bearer token" https://api.example.com/data
Handling JSON Data
Sending JSON Data
curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' https://api.example.com/data
Fetching and Parsing JSON Response (using jq)
curl -s https://api.example.com/data | jq .
Handling Cookies
Saving Cookies to File
curl -c cookies.txt https://example.com
Using Cookies File
curl -b cookies.txt https://example.com
Using a Proxy
curl -x http://proxy.example.com:8080 https://api.example.com/data
Limiting Bandwidth
curl --limit-rate 100K https://example.com/file.zip -O
Resuming Downloads
curl -C - -O https://example.com/largefile.zip
Verifying SSL Certificate
curl --cacert /path/to/ca-bundle.crt https://secure.example.com
Common Issues
1. cURL Command Not Running
- Solution: Check if cURL is correctly installed and ensure the configuration file paths are correct. If the issue persists, review the error logs for more information.
2. Errors in Sending Requests
- Solution: Verify the URL and parameters of the request are correct. Ensure the network connection is stable and that the target server is accessible.
3. File Download or Upload Failure
- Solution: Check that file paths and permissions are correct. Ensure the target server supports the respective file transfer operations.
4. SSL Certificate Verification Failure
- Solution: Ensure the correct CA certificate file is used. The
--insecure
option can be used to ignore SSL certificate verification (not recommended for production environments).
curl --insecure https://secure.example.com
Summary
cURL is a powerful and flexible command-line tool suitable for various data transfer tasks. This article has introduced how to install, configure, and use cURL in ServBay for HTTP requests, file downloads, and API calls.