user3264461 user3264461 - 5 months ago 116
reST (reStructuredText) Question

GuzzleHttp Hangs When Using Localhost

Here is a simple code snipplet but this just hangs and unresponsive.

$httpClient = new GuzzleHttp\Client(); // version 6.x

$headers = ['X-API-KEY' => '123456'];

$request = $httpClient->request('GET', 'http://localhost:8000/BlogApiV1/BlogApi/blogs/', $headers);
$response = $client->send($request, ['timeout' => 2]);

echo $request->getStatusCode();
echo $request->getHeader('content-type');
echo $request->getBody();

Any pointers much appreciated. When I tried above with the github api using my username and password, I do get a 200 response and a lot of info.


Finally resolved it. Guzzle (or CURL to be specific) is denying the requests if you're running from non-standard ports.

Also, this appears to be random, sometime it works, sometime it doesn't. I moved to port 80 and Voila everything worked.