Guzzle: Guzzle return `502 Bad Gateway` error on some urls

Created on 18 Jun 2018  路  4Comments  路  Source: guzzle/guzzle

I have try this api url to get response but Guzzle return me 502 status code:

$url = https://www.aparat.com//etc/api/mostviewedvideos;
$guzzle = new Client;
$response = $guzzle->get($url)->getBody();

This code works find with other urls

kinsupport resolutioinvalid

Most helpful comment

I had same problem with aparat API.
I solved problem by removing User-Agent from request.

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://www.aparat.com/etc/api/video/videohash/rzKus', [
    headers' => ['User-Agent' => null]
]);

All 4 comments

5xx errors indicate server side errors.

Besides, quotes are missing: $url = 'https://www.aparat.com//etc/api/mostviewedvideos';

same problem here.

i do it with a simple curl and its work, but with guzzle its return 502 error,

my code :

`
$client = new GuzzleHttp\Client();

    try {
        $response = $client->request('GET', $url, [ "query" => $params ]);
        $resbody = $response->getBody()->getContents();

        if ( $parviz->is_json($resbody) ) {
            $jobj = json_decode($resbody);
            return $jobj;
        } else {
            return false;
        }
    } catch (GuzzleHttp\Exception\ClientException $e) { return false; }

`

I had same problem with aparat API.
I solved problem by removing User-Agent from request.

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://www.aparat.com/etc/api/video/videohash/rzKus', [
    headers' => ['User-Agent' => null]
]);

$client = new GuzzleClient();
$response = $client->request('GET', 'http://httpbin.org/get');

Above is giving 502 Bad Gateway always. Can't seem to resolve this. Please help.

Was this page helpful?
0 / 5 - 0 ratings