admin管理员组文章数量:1123407
I am trying to receive data from my API using socks5 proxy with curl and PHP.
But no matter what I try, I get this error Received invalid version in initial SOCKS5 response
I've tried google all I can, none come up with a fix. I tried all the solutions they list, but all returns this error.
This is my current code
<?php
function fetchContent($url) {
$proxy = 'socks5h://domain:22';
$proxyAuth = 'username:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
}
fetchContent('');
?>
As extra info, I am using same socks5 proxy over SSH on my laptop with putty tunnel to connect around and that works fine.
I am trying to receive data from my API using socks5 proxy with curl and PHP.
But no matter what I try, I get this error Received invalid version in initial SOCKS5 response
I've tried google all I can, none come up with a fix. I tried all the solutions they list, but all returns this error.
This is my current code
<?php
function fetchContent($url) {
$proxy = 'socks5h://domain.com:22';
$proxyAuth = 'username:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
}
fetchContent('https://ipinfo.io/ip');
?>
As extra info, I am using same socks5 proxy over SSH on my laptop with putty tunnel to connect around and that works fine.
Share Improve this question edited 15 hours ago HDIK asked 15 hours ago HDIKHDIK 531 silver badge6 bronze badges 2- 1 SOCKS5 proxies typically run on ports like 1080, not SSH ports like 22, check that first, and then If the proxy doesn't support the socks5h protocol (which resolves DNS over the proxy), you might need to use socks5 instead. – TSCAmerica.com Commented 13 hours ago
- @TSCAmerica.com I have tried with socks5 too, it is still the same. About the port, I am trying to use sucks5 over the SSH protocol and the uses listens for SSH connection on that port. It works with the local tunnel on my putty which creates the tunnel over SSH, but I am not trying to create a tunnel with the script, just proxying the request thru the IP. Is it me that totally wrong here expecting that I can use the same method with curl? – HDIK Commented 13 hours ago
1 Answer
Reset to default 0By default, curl uses CURLPROXY_HTTP
for CURLOPT_PROXYTYPE
option.
To use socks5h
you need to set CURLOPT_PROXYTYPE
to CURLPROXY_SOCKS5_HOSTNAME
<?php
# ... your code ...
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
# ... your code ...
P.S. Consider to remove protocol from proxy adddres definition
<?php
$proxy = 'domain.com:22';
本文标签: Received invalid version in initial SOCKS5 response php curlStack Overflow
版权声明:本文标题:Received invalid version in initial SOCKS5 response php curl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736569210a1944748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论