squid curl_如何使curl请求通过Squid代理?

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);
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-make-curl-request-pass-the-squid-proxy/

squid curl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值