public function send()
{
// make a request object
$this->request = $this->client->createRequest($this->method, $this->host . $this->resource);
// set headers
foreach ($this->headers as $header => $value) {
$this->request->setHeader($header, $value);
}
// set body
if (!empty($this->body)) {
$this->request->setBody($this->body);
}
try {
// finally send the request
$this->response = $this->client->send($this->request);
} catch (BadResponseException $e) {
// if the response is an 40x or a 50x then it will throw an exception
// we catch and get the response stored on the request object
$this->response = $this->request->getResponse();
}
$this->sent = true;
}