Performing Http Requests With Curl (Using 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/

Force cURL to use GET on proxy for HTTPs requests

I don't believe this can be done using some common configuration setting on the client side as it would deny the whole purpose of HTTPS (that no one can eavesdrop your HTTPS traffic).

Your only option is thus to configure your proxy to basically create a man-in-the-middle attack to decrypt the HTTPS traffic going through it. Squid proxy should support this using their "SSL bump" feature. There is a nice intro for it on this wiki and more setup docs here.

What squid does in this regime is that it gets the address of the remote server from the client's CONNECT request and instead of creating just a blind tunnel to the server, it starts a new direct HTTPS request to the server by itself and saves the reply. Thus Squid has access to all the traffic and can cache it or do anything else Squid can do with it.

When sending replies back to the client, it itself needs to present a HTTPS certificate (the client expects HTTPS traffic), so in Squid there is a feature to automatically generate certificates for all proxied domains. To configure it you will essentially have to create a local Certificate Authority. Note that these auto-generated certificates will be simple self-signed certificates so, on the client side, this will look as untrusted certificates and you'll need to switch off peer verification (CURLOPT_SSL_VERIFYPEER = false).

I could not find any similar feature in Apache traffic server. They seem to support only SSL termination in the reverse proxy mode.

Last note: please bear in mind that this is still rather a hack and decrypting HTTPS may bring legal or ethical problems. Never do this without the clients consent!

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

Running Curl Command in Jenkins Behind Corporative Proxy

Since Jenkins is behind the corporate proxy, you have to pass proxy information to curl to connect to target services.

curl man page says, you can pass proxy information with either --proxy or -x(shortcut) argument.

sh '''
curl -s --proxy <protocol>://<proxy-host>:<proxy-port> -X \
POST https://api.telegram.org/bot${TOKEN}/sendMessage \
-d chat_id=${CHAT_ID} \
-d parse_mode="HTML" \
-d text=" <b>Jenkins CI:</b> <b>Iniciando build $BUILD_DISPLAY_NAME</b> $JOB_NAME"
'''

This can also set via env vars http_proxy/https_proxy.

In case if proxy expects basic auth, it can be passed like <protocol>://<proxy-username>:<proxy-password@><proxy-host>:<proxy-port>

Finally, while debugging curl, it's important to remove -s argument as it silently mutes the output.



Related Topics



Leave a reply



Submit