Beispiel #1
1
    public function testToStringFormatsTheRequest()
    {
        $request = new Request('POST', '/resource/123', 'http://example.com');
        $request->setProtocolVersion(1.1);
        $request->addHeader('Content-Type: application/x-www-form-urlencoded');
        $request->setContent('foo=bar&bar=baz');
        $expected = <<<EOF
POST /resource/123 HTTP/1.1
Host: http://example.com
Content-Type: application/x-www-form-urlencoded

foo=bar&bar=baz

EOF;
        $this->assertEquals((string) $request, $expected);
    }
Beispiel #2
1
 public function authorizeClient($clientId, $clientSecret, $scope)
 {
     $query = array('client_id' => $clientId, 'scope' => $scope, 'grant_type' => 'client_credentials');
     $request = new Request(Request::METHOD_POST, '/token/');
     $request->addHeader('Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret));
     $request->setContent(http_build_query($query));
     return $this->send($request, null, false);
 }
 /**
  * HTTP POST METHOD (static)
  *
  * @param  string $url
  * @param  array $params
  * @param  array $headers
  * @param  mixed $body
  * @param  array|Traversable $clientOptions
  * @throws Exception\InvalidArgumentException
  * @return Response|bool
  */
 public static function post($url, $params, $headers = [], $body = null, $clientOptions = null)
 {
     if (empty($url)) {
         return false;
     }
     $request = new Request();
     $request->setUri($url);
     $request->setMethod(Request::METHOD_POST);
     if (!empty($params) && is_array($params)) {
         $request->getPost()->fromArray($params);
     } else {
         throw new Exception\InvalidArgumentException('The array of post parameters is empty');
     }
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = Client::ENC_URLENCODED;
     }
     if (!empty($headers) && is_array($headers)) {
         $request->getHeaders()->addHeaders($headers);
     }
     if (!empty($body)) {
         $request->setContent($body);
     }
     return static::getStaticClient($clientOptions)->send($request);
 }