How to use a SOCKS 5 proxy with cURL?(如何使用带有 cURL 的 SOCKS 5 代理?)
问题描述
普通代理(例如:72.41.132.22:3128
)与 cURL 配合良好,但是当我使用带有用户名/密码的 SOCKS 5 代理时,它只会在页面上显示[1".
Normal proxies (ex: 72.41.132.22:3128
) work well with cURL, however when I use SOCKS 5 proxies with username/pass, It just gives me "[1" on the page.
有没有办法在 cURL 中使用 SOCKY 5 代理?
Is there a way to use SOCKY 5 proxies with cURL ?
$proxy = "cagsan:jw22wdw@108.61.25.223:34792";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
推荐答案
你需要告诉 cURL 代理是一个 SOCKS5 代理,否则 cURL 假定它是一个 HTTP 代理:
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);
来自文档:
CURLOPT_PROXYTYPE
CURLPROXY_HTTP(默认)或 CURLPROXY_SOCKS5.
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
这篇关于如何使用带有 cURL 的 SOCKS 5 代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用带有 cURL 的 SOCKS 5 代理?


基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01