performing HTTP requests with cURL (using PROXY)

LinuxCurlProxy

Linux Problem Overview


I have this proxy address: 125.119.175.48:8909

How can I perform a HTTP request using cURL like curl http://www.example.com, but specifying the proxy address of my network?

Linux Solutions


Solution 1 - Linux

From man curl:

-x, --proxy <[protocol://][user:password@]proxyhost[:port]>

     Use the specified HTTP proxy. 
     If the port number is not specified, it is assumed at port 1080.

Solution 2 - Linux

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/

Solution 3 - Linux

The above solutions might not work with some curl versions I tried them for myself(curl 7.22.0). But what worked for me was:

curl -x http://proxy_server:proxy_port --proxy-user username:password -L http://url

Hope it solves the issue better!

Solution 4 - Linux

Beware that if you are using a SOCKS proxy, instead of a HTTP/HTTPS proxy, you will need to use the --socks5 switch instead:

curl --socks5 125.119.175.48:8909 http://example.com/

You can also use --socks5-hostname instead of --socks5 to resolve DNS on the proxy side.

Solution 5 - Linux

as an adition to airween, another good idea is to add this into your .bashrc, so you'll be able to switch from non proxied to proxied environment:

alias proxyon="export http_proxy='http://YOURPROXY:YOURPORT';export https_proxy='http://YOURPROXY:YOURPORT'"
alias proxyoff="export http_proxy='';export https_proxy=''"

WHERE YOURPROXY:YOURPORT is exactly that, your ip and port proxy :-).

Then, simply doing

proxyon

your system will start to use the proxy, and just the opposite with:

proxyoff

Solution 6 - Linux

use the following

curl -I -x 192.168.X.X:XX http://google.com

192.168.X.X:XX put your proxy server ip and port.

-v verbose mode it will give more details including headers and response.

Solution 7 - Linux

I like using this in order to get the IP under which I am seen

curl -x http://proxy_server:proxy_port https://api.ipify.org?format=json && echo

Hope this helps someone.

Solution 8 - Linux

For curl you can configure proxy in your ~/.curlrc (_curlrc on Windows) file by adding proxy value, the syntax is:

proxy = http://username:password@proxy-host:port

Solution 9 - Linux

curl -I "https://www.google.com" -x 1.1.1.1:8080

Solution 10 - Linux

Just summarizing all great mentioned answers:

curl -x http://<user>:<pass>@<proxyhost>:<port>/ -o <filename> -L <link>

Solution 11 - Linux

With a proxy with authentication I use:

curl -x <protocol>://<user>:<password>@<host>:<port> --proxy-anyauth <url>

because, I don't know why curl doesn't use/catch http[s]_proxy environment variables.

Solution 12 - Linux

You don't need to export the http[s]_proxy shell variable if you're just setting the proxy for a one off command. e.g.

http_proxy=http://your.proxy.server:port curl http://www.example.com

That said, I'd prefer curl -x if I knew I was always going to use a proxy.

Solution 13 - Linux

curl -vv -ksL "https://example.com" -x "http://<proxy>:<port>"

Solution 14 - Linux

sudo curl -x http://10.1.1.50:8080/ -fsSL https://download.docker.com/linux/ubuntu/gpg

> This worked perfectly for me, the error comes because curl need to set > the proxy > > Remmember replace the proxy with your proxy, mine, "example" was > http://10.1.1.50:8080/.

Solution 15 - Linux

Depending on your workplace, you may also need to specify the -k or the --insecure option for curl in order to get past potential issues with CA certificates.

curl -x <myCompanyProxy>:<port> -k -O -L <link to file to download>

Solution 16 - Linux

In case the proxy is using automatic proxy with PAC file. We can find the actual proxy from the javascript from the PAC URL.

And if the proxy needs authentication, we can first use a normal web-browser to access the website which will promote authentication dialog. After authentication, we can use wireshark to capture the http package sends to the proxy server, from the http package, we can get the auth token from http header: Proxy-Authorization

Then we can set the http_proxy environment variable and also include auth token in the http header: Proxy-Authorization

export http_proxy=http://proxyserver:port

curl -H "Proxy-Authorization: xxxx" http://targetURL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser873286View Question on Stackoverflow
Solution 1 - LinuxKarl BarkerView Answer on Stackoverflow
Solution 2 - LinuxairweenView Answer on Stackoverflow
Solution 3 - LinuxAmarView Answer on Stackoverflow
Solution 4 - LinuxFilipe CorreiaView Answer on Stackoverflow
Solution 5 - LinuxAlejandro MorenoView Answer on Stackoverflow
Solution 6 - Linux13krnView Answer on Stackoverflow
Solution 7 - LinuxbmetgeView Answer on Stackoverflow
Solution 8 - LinuxkenorbView Answer on Stackoverflow
Solution 9 - LinuxDebashish SahaView Answer on Stackoverflow
Solution 10 - LinuxMorteza MashayekhiView Answer on Stackoverflow
Solution 11 - LinuxPedro R. Sánchez A.View Answer on Stackoverflow
Solution 12 - LinuxoverthinkView Answer on Stackoverflow
Solution 13 - Linuxiamtheexp01View Answer on Stackoverflow
Solution 14 - LinuxIbarMarioView Answer on Stackoverflow
Solution 15 - LinuxMatt LeglerView Answer on Stackoverflow
Solution 16 - LinuxJianwu ChenView Answer on Stackoverflow