How to Set Up Curl to Permanently Use a Proxy

How do I set up curl to permanently use a proxy?

You can make a alias in your ~/.bashrc file :

alias curl="curl -x <proxy_host>:<proxy_port>"

Another solution is to use (maybe the better solution) the ~/.curlrc file (create it if it does not exist) :

proxy = <proxy_host>:<proxy_port>

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/

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.)

How to configure cURL to use client proxy?

For libcurl, use CURLOPT_PROXY:

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXY

For the curl command line tool, use option --proxy host:port.

Both the library and the command line tool respect the environment variables http_proxy, ftp_proxy, all_proxy, so that's another option.

Edit:
If you want to use the client's proxy on the server - this won't work reliably.
First, you would need to determine client's proxy settings via javascript - which might work.
Second, you would need to use that proxy to make a request on the server - this will certainly not work reliably, as the client's proxy might be in a local network (not accessible from outside), require authentication etc.

An option would be to make a client request via JavaScript (AJAX) and verify the result - which is a somewhat questionable approach, as you are making requests from your client's computers to possibly blocked (illegal?) sites. Better don't do that.

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

HTTP_PROXY not working

curl only supports the http_proxy environment variable for setting the proxy for HTTP with the environment. Lowercase being the key and vital difference.

curl does not acknowledge the uppercase version of that variable for security purposes: that variable can be set by an incoming request in a CGI environment.



Related Topics



Leave a reply



Submit