Example #1
0
 /**
  * Creates a request.
  *
  * @param string $server Server
  * @param string $path Path
  * @param integer $method Request method
  * @param array $headers Array of headers
  * @return \http\Client\Request
  */
 protected function createRequest($server, $path, $method, array $headers = array())
 {
     $request = new \http\Client\Request($method, $server . $path);
     $request->setOptions($this->curlOptions);
     $request->setSslOptions($this->curlSslOptions);
     $request->setHeaders($headers + array('Expect' => ''));
     return $request;
 }
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}');
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array('content-type' => 'application/json'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Example #3
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append('Hello World');
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array('content-type' => 'text/plain'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Example #4
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('GET');
$request->setHeaders(array('x-foo' => 'Bar', 'accept' => 'application/json'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Example #5
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(new http\QueryString(array('foo' => 'bar')));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setQuery(new http\QueryString(array('foo' => array('bar', 'baz'), 'baz' => 'abc', 'key' => 'value')));
$request->setHeaders(array('content-type' => 'application/x-www-form-urlencoded', 'accept' => 'application/json'));
$client->setCookies(array('bar' => 'baz', 'foo' => 'bar'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();