S
S
santavits2018-07-29 15:32:10
PHP
santavits, 2018-07-29 15:32:10

Why is there a different api response?

Such a problem
There is a service, orders are transferred to it via api, if you manually create a request and run it in the browser, then I get the answer as it should, if through the php script there, for example, through curl or file_get_contents, then the answer is completely different, the left error generally comes out.
How can this problem be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Terekhin, 2018-07-30
@RomaZveR

curl_setopt($ch, CURLOPT_urlERER, $url); //Это чего такое?

Judging by the fact that both curl and file_get_contents are falling, you do not have OpenSSL connected to php. And the root certificate is not configured for the curl.
Try like this. See what error the curl will give.
$ua = 'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Widows NT)';
$url = "https://sites.ru/api/index.php?key=apikey&action=create&service=295&quantity=1&link=111";
 
$ch = curl_init($url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
      curl_setopt($ch, CURLOPT_USERAGENT, $ua);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); //Можете поставить в 0, но это риск mitm.
      curl_setopt($ch, CURLOPT_URL, $url);
$buf = curl_exec ($ch);

 // Проверяем наличие ошибки.
if (curl_errno($ch)) {
     //На продакшене заменить логгированием. 
     echo 'Ошибка curl: ' . curl_error($ch);
}
curl_close ($ch);
     
echo $buf;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question