如何使用SOCKS 5代理与cURL? [英] How to use a SOCKS 5 proxy with cURL?

查看:235
本文介绍了如何使用SOCKS 5代理与cURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正常代理(例如: 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.

有没有办法使用SOCKY 5代理与cURL?

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);

docs


CURLOPT_PROXYTYPE b


CURLPROXY_HTTP(默认)或CURLPROXY_SOCKS5。

Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.


这篇关于如何使用SOCKS 5代理与cURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆