403 вызов api.weather.gov с использованием клиента Buzz с https

Попытка использовать curl / file_get_contents с помощью Buzz в моем приложении Symfony для извлечения данных, например, из того, что вы могли увидеть здесь:

https://api.weather.gov/points/44.3537,-73.8636/forecast/hourly

Неважно, что, я, кажется, получаю 403 Запрещенную ошибку, и мне интересно, есть ли у кого-нибудь совет?

    $location = sprintf(
'/points/%f,%f/forecast/hourly', $this->latitude, $this->longitude
);

$request  = new Request('GET', $location, 'https://api.weather.gov');
$response = new Response();

try {
$this->httpClient->send($request, $response);
} catch (\Exception $e) {
throw new ServiceResponseException('Failed to send Request', 0, $e);
}

if (!$response->isSuccessful()) {
throw new ServiceResponseException('Unsuccessful Response', $response->getStatusCode());
}

return $response->getContent();

В классе Buzz ‘FileGetContents

$url = $request->getHost().$request->getResource();

$ url оценивается как:
https://api.weather.gov/points/44.353700,-73.863600/forecast/hourly

То же самое с CURL

Заголовки вернулись

Array ( [0] => HTTP/1.1 403 Forbidden [1] => Server: AkamaiGHost [2] => Mime-Version: 1.0 [3] => Content-Type: text/html [4] => Content-Length: 334 [5] => Expires: Thu, 13 Apr 2017 14:15:56 GMT [6] => Date: Thu, 13 Apr 2017 14:15:56 GMT [7] => Connection: close )

0

Решение

Вам нужно установить Accept, Version, а также User-Agent заголовки.

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector