curl through a proxy: -x, environment variables, SOCKS and no_proxy
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
In a corporate network requests often go through a proxy and curl must know about it. The proxy is set with -x or environment variables, and internal addresses are excluded with no_proxy. Below are commands and the usual errors when curl cannot connect through the proxy or uses it when it should not.
The -x flag and environment variables
-x host:port sets a proxy for one request. To avoid typing it every time, set http_proxy and https_proxy. For addresses that must go direct, such as internal services and localhost, fill no_proxy with a comma-separated list.
SOCKS5 and auth
For SOCKS5 put the scheme in the proxy URL: socks5h:// resolves names on the proxy side, socks5:// locally. Proxy login and password go with -U or in the proxy URL. Encode special characters in the password or curl misparses the URL.

When the proxy gets in the way
If an internal service fails while outside sites work, the request probably went to the proxy from environment variables. Check with -v which address curl connects to, and add the service to no_proxy or disable the proxy for the request with --noproxy and an asterisk.
Proxy commands
# прокси для одного запроса
curl -x http://proxy.corp.local:3128 https://api.example.com/health
# прокси с логином и паролем
curl -x http://proxy.corp.local:3128 -U "ivan:пароль" https://api.example.com/health
# SOCKS5, имена резолвит прокси
curl -x socks5h://127.0.0.1:1080 https://api.example.com/health
# переменные окружения (Linux, macOS)
export https_proxy=http://proxy.corp.local:3128
export http_proxy=http://proxy.corp.local:3128
export no_proxy=localhost,127.0.0.1,.corp.local
# не использовать прокси для этого запроса
curl --noproxy "*" http://erp.corp.local/healthOn Windows set variables with set in cmd or $env: in PowerShell. Case matters for http_proxy: curl reads it only in lowercase.

Errors through a proxy
| Symptom | What to check |
|---|---|
| 407 Proxy Authentication Required | Proxy login and password, -U |
| Could not resolve proxy | Proxy address, DNS, a typo in the variable |
| Internal service does not open | no_proxy; the request went to the proxy |
| SSL certificate problem | The proxy intercepts TLS; pass the corporate root with --cacert |
More on curl
Section overview and all guides: curl command cheat sheet: flags and examples for APIs.
- PHP cURL: GET and POST requests with JSON, headers and error handling
- Webhook: what it is, how it works and how to test it
- curl GET request: parameters, response headers and status code
- cURL examples: GET and POST requests with JSON on Linux, Windows and PowerShell
- Headers in curl: Content-Type application/json, Accept and multiple -H
Frequently asked questions
How do I set a proxy in curl?
-x host:port or the http_proxy and https_proxy variables.
How do I disable the proxy?
--noproxy "*" for one request or add the host to no_proxy.
How do I use SOCKS5?
socks5h://host:port so the proxy resolves names.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.