Skip to content
CheckcraftDownload
Practical workflow

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.

Checkcraft ·

Get help with your first test →

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.

API call diagram: method and URL, headers, body, status and response body, logs and database

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/health

On Windows set variables with set in cmd or $env: in PowerShell. Case matters for http_proxy: curl reads it only in lowercase.

Layers of an API call check: status, headers, body, calculations, logs, database

Errors through a proxy

SymptomWhat to check
407 Proxy Authentication RequiredProxy login and password, -U
Could not resolve proxyProxy address, DNS, a typo in the variable
Internal service does not openno_proxy; the request went to the proxy
SSL certificate problemThe 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.

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.

Next step

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 run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

curl man page

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.