我刚刚完成第一次安装guzzle并试图进行第一次测试。我从网上复制了一个简单的例子并试图运行它,但由于某种原因我得到以下错误:
GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: api (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我在浏览器中检查了地址,请求返回了这个json:
{"status":{"Production":"green","Development":"green"},"issues":[]}
代码如下所示:
require dirname(__FILE__).'/../../src/vendor/autoload.php';
use GuzzleHttp\Client;
class ApiTest extends PHPUnit_Framework_TestCase
{
/**
* Tests heroku status is green
*/
public function testHerokuStatus()
{
$client = new Client(['base_url' => 'https://status.heroku.com']);
$request = $client->get('api/v3/current-status');
$response = $request;
$decodedResponse = $response->json();
$this->assertEquals($decodedResponse['status']['Production'], 'green');
$this->assertEquals($decodedResponse['status']['Development'], 'green');
}
}
为什么guzzle会产生这个错误? THX
更新
当我尝试在/
的开头添加$client->get
时出现此错误:
1) ApiTest::testHerokuStatus
GuzzleHttp\Exception\RequestException: cURL error 3: <url> malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
如果它有任何帮助