Zend \ Http \ Client调用localhost(服务器端)

时间:2015-11-12 15:38:57

标签: php zend-framework

我正在开发一个中型Zend Framework 2项目(LAMP),我需要在本地执行ajax调用(例如:http://localhost/api/myapi)。

这是函数的代码:

        private function getSettings() {
            $client = new HttpClient();

            $client->setAdapter('Zend\Http\Client\Adapter\Curl');
            $client->setMethod('GET');

            $client->setUri('http://localhost/api/settings/0');

            $config = array(
                    'curloptions' => array(CURLOPT_SSL_VERIFYPEER => false),
                    'timeout' => 3000000
            );

            $client->setOptions($config);

            $requestHeaders = $client->getRequest()->getHeaders();
            $requestHeaders->addHeaderLine('Accept: application/json');

            $resp = $client->send();

            return $resp->getContent();
    }

我的问题是,当我执行此功能时,我收到此错误:

  

在此服务器上找不到请求的URL / api / settings / 0

我做错了什么?我怎样才能表演"本地"请求使用ZF2的Http客户端类?

0 个答案:

没有答案