How to Use Curl Via a Proxy

performing HTTP requests with cURL (using PROXY)

General way:

export http_proxy=http://your.proxy.server:port/

Then you can connect through proxy from (many) application.

And, as per comment below, for https:

export https_proxy=https://your.proxy.server:port/

curl through proxy syntax

Ignore "[" when reading general syntax. Also, windows likes double vs single quotes.

So the command is:

curl -x my-host-which-i-know:my-port-which-i-know -U my-username-which-i-know:my-pass-which-i-know http://www.google.com

How do I make curl ignore the proxy?

I assume curl is reading the proxy address from the environment variable http_proxy and that the variable should keep its value. Then in a shell like bash, export http_proxy=''; before a command (or in a shell script) would temporarily change its value.

(See curl's manual for all the variables it looks at, under the ENVIRONMENT heading.)

curl HTTPS via an SSH proxy

Try using a socks5 proxy for example:

$ ssh -D 8080 -f -C -q -N user@remote.host
  • -D 8080 tells ssh to launch a SOCKS server on port 8080 locally.
  • -f Forks the process to the background.
  • -C Compresses the data before sending it.
  • -q Uses quiet mode.
  • -N Tells SSH that no command will be sent once the tunnel is up.

Then you could use curl like this:

curl -x socks5h://0:8080 https://example.com


Related Topics



Leave a reply



Submit