/** * Creates a new HTTP POST request with the appropriate content, headers * and such, which can then be used to send JSON-RPC requests. * @param string $content the request content * @return \Zend\Http\Request the request * @throws ClientException if the Content-Type header cannot be set */ private function createHttpRequest($content) { $httpRequest = new \Zend\Http\Request(); $httpRequest->setUri($this->_endPoint); $httpRequest->setMethod(\Zend\Http\Request::METHOD_POST); $httpRequest->setContent($content); // Set headers $headers = $httpRequest->getHeaders(); if (!$headers instanceof \Zend\Http\Headers) { throw new ClientException('Unable to configure HTTP headers'); } $headers->addHeaderLine('Content-Type', 'application/json'); $httpRequest->setHeaders($headers); return $httpRequest; }
public static function sendRequest($url, $postString = '', $method = \Zend\Http\Request::METHOD_POST) { $client = new \Zend\Http\Client(); $client->setAdapter(new \Zend\Http\Client\Adapter\Curl()); $request = new \Zend\Http\Request(); $request->setUri($url); $request->setMethod($method); if (is_array($postString)) { $params = $postString; $postString = ''; foreach ($params as $key => $value) { $postString .= $key . '=' . urlencode($value) . '&'; } $postString = substr($postString, 0, strlen($postString) - 1); } $request->setContent($postString); $response = $client->dispatch($request); return $response->getContent(); }