squid curl
I use curl to send requests to remote servers like following command.
我使用curl将请求发送到远程服务器,例如以下命令。
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.
Linux上的curl命令和使用libcurl库构建的程序也会发生类似的情况。
If I change the request from POST to GET as follows
如果我将请求从POST更改为GET,如下所示
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?
这是怎么了?如何使curl请求通过Squid代理?
The problem is that Squid doesn’t support Expect: 100-continue
.
问题是Squid不支持Expect: 100-continue
。
You can overwrite it in curl command by setting the header:
您可以通过设置头在curl命令中覆盖它:
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);
翻译自: https://www.systutorials.com/how-to-make-curl-request-pass-the-squid-proxy/
squid curl