K
K
kr_ilya2019-01-08 14:41:02
PHP
kr_ilya, 2019-01-08 14:41:02

Failed to receive SOCKS5 connect request ack. When accessing the Telegram Bot API via cURL?

I turn to the Telegram Bot API with cURL and there are times when it returns this error
Failed to receive SOCKS5 connect request ack.
There is no such problem on OpenServer.
Everything happens on a hosting (hts) with a trial period.
I can not understand what could be the problem ...
Here is the code

function sendMessage($imgUrl, $text, $link){
  $ch = curl_init();
  $pr = array('u0k12.tgproxy.me', 'sr.spry.fail', 'sr123.spry.fail', 'd2a5e5.reconnect.rocks');
$x= 0;
$cnt = count($pr);
do{
//Проверяем доступность proxy
$host = $pr[$x]; 
$port = 1080; 
$waitTimeoutInSeconds = 1;
$x++; 
if($fp = fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)){   
   $a = 1; //если ping proxy меньше 1 секунды
} else {
   $a = 0;
} 
fclose($fp);
}while($a !== 1);
$user = 'TELEGRAM';
$pas = 'TELEGRAM';
if($host == 'd2a5e5.reconnect.rocks')
{$pas = '11a1fcc2';$user = '3559738';}

$proxy = $user.":".$pas."@".$host.":".$port;
$url = "https://api.telegram.org/botToken/sendMessage?chat_id=Chatid&parse_mode=Markdown&text=text;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "socks5://".$proxy);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);

$err = curl_error($ch);
if (!empty($err))
return $err;

return $result;
}

ps: Proxies are taken from a public source.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0ffff0, 2019-01-08
@0ffff0

It is my deep conviction that
you need to specify cURL, a SOCKS5 proxy, for your hts with a trial period, otherwise cURL assumes an HTTP proxy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question