How to use a SOCKS 5 proxy with cURL?

老子叫甜甜 提交于 2019-11-30 01:13:00

You need to tell cURL the proxy is a SOCKS5 proxy, otherwise cURL assumes it's an HTTP proxy:

curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

From the docs:

CURLOPT_PROXYTYPE

Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.

GiDo

since cURL 7.21.7, you can use CURLOPT_PROXY and specify the SOCKS protocol:

curl_setopt($ch, CURLOPT_PROXY, 'socks5://bob:marley@localhost:12345');

More informations in the libcurl documentation.

For those looking to connect via a hostname(localhost?), and it's not working with CURLPROXY_SOCKS5, you can try CURLPROXY_SOCKS5_HOSTNAME.

curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);

In some earlier PHP versions, you will have to do:

curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!