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?

asked Apr 28, 2015 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

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);
answered Apr 29, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...