Этот curl запрос в терминале работает, добавляет зеркала:
curl -X PUT https://api-metrika.yandex.net/management/v1/counter/COUNTER_VAR -H "Host: api-metrika.yandex.net" -H "Authorization: OAuth TOKEN_VAR" -H "Content-Type: application/x-yametrika+json" -d '{"counter":{"mirrors2":[{"site":"test.example.com"},{"site":"test2.example.com"},{"site":"test3.example.com"},{"site":"test4.example.com"},{"site":"test5.example.com"}]}}'
Этот на PHP не работает:
$url = "https://api-metrika.yandex.net/management/v1/counter/$COUNTER_VAR";
$headers = [
"Host: api-metrika.yandex.net",
"Authorization: OAuth $TOKEN_VAR",
"Content-Type: application/x-yametrika+json",
];
$data = '{"counter":{"mirrors2":[{"site":"test.example.com"},{"site":"test2.example.com"},{"site":"test3.example.com"},{"site":"test4.example.com"},{"site":"test5.example.com"}]}}';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
Отдает почти моментально на одном сервере:
bool (false)
На другом сервере через 30 секунд отдает:
string(389) "{"errors":[{"error_type":"invalid_json","message":"I/O error while reading input message; nested exception is java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30000/30000 ms"}],"code":400,"message":"I/O error while reading input message; nested exception is java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30000/30000 ms"}"