Comprehensive troubleshooting guide for cURL error codes. Learn how to fix exit code 6 (DNS failure), code 7 (Connection refused), code 28 (Timeout), code 35 (SSL error), and code 60 (Certificate untrusted).
Frequently Asked Questions
Q1. How do I check the cURL exit status code in bash scripts?
In bash or sh, evaluate the $? variable immediately after running the curl command: curl https://api.example.com; if [ $? -ne 0 ]; then echo "cURL failed with code $?"; fi.
Q2. Is it safe to use curl -k (insecure) in production?
No. The -k or --insecure flag disables all SSL/TLS certificate verification, leaving your communication vulnerable to Man-in-the-Middle (MITM) attacks and credential theft. Only use -k on local development environments (localhost).
Q3. How do I tell cURL to automatically retry on network failures?
Use --retry <num> combined with --retry-delay <seconds> and --retry-connrefused: curl --retry 3 --retry-delay 2 --retry-connrefused https://api.example.com.
Q4. How do I fix curl: (52) Empty reply from server?
Error 52 occurs when the server accepts the TCP connection but terminates it before sending any HTTP response bytes. This usually indicates a crashed backend worker (e.g., Nginx upstream 502/crashed PHP-FPM or Node.js process) or an incorrect HTTPS scheme sent to an HTTP-only port.