Answer the question
In order to leave comments, you need to log in
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
curl_setopt($ch, CURLOPT_urlERER, $url); //Это чего такое?
$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 questionAsk a Question
731 491 924 answers to any question