How to make curl request pass the Squid proxy?

I use curl to send requests to remote servers like following command.

curl http://example.com/send --date-urlencode "data=hello"

However, it is blocked by the network proxy squid in some networks with message like (some info anonymized with “…”):

ERROR
The requested URL could not be retrieved

POST /... HTTP/1.1
Proxy-Authorization: Basic ...
User-Agent: Mozilla/4.0 (compatible;)
Host: ...
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 87022
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------...

Similar things happen for the curl command on Linux and programs built with the libcurl library.

If I change the request from POST to GET as follows

curl -G http://example.com/send --date-urlencode "data=hello"

Then the request can pass the proxy just well.

What’s wrong here and how to make the curl request pass the Squid proxy?

The problem is that Squid doesn’t support Expect: 100-continue.

You can overwrite it in curl command by setting the header:

curl http://example.com/send -H "Expect:" --date-urlencode "data=hello"

Or in your code by

CURL *curl = curl_easy_init();
struct curl_slist *list = NULL;
list = curl_slist_append(list, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);

// remember to free the list
curl_slist_free_all(list);

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *