/** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->buildRateRequest(); $options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->accessRequest . $this->rateRequest, CURLOPT_HEADER => false); if (!$verifyPeer) { $options[CURLOPT_SSL_VERIFYPEER] = false; } $curl = new Curl($this->url, $options); $curl->execute(); $this->response = simplexml_load_string($curl->getBody()); $this->responseCode = (int) $this->response->Response->ResponseStatusCode; if ($this->responseCode == 1) { $this->responseMessage = (string) $this->response->Response->ResponseStatusDescription; foreach ($this->response->RatedShipment as $rate) { $this->rates[self::$services[(string) $rate->Service->Code]] = (string) $rate->TotalCharges->MonetaryValue; } } else { $this->responseCode = (string) $this->response->Response->Error->ErrorCode; $this->responseMessage = (string) $this->response->Response->Error->ErrorDescription; } }
<?php require_once '../../bootstrap.php'; use Pop\Curl\Curl; try { $curl = new Curl('http://pop.localhost/examples/curl/curl-process.php'); $curl->setPost(true); $curl->setFields(array('name' => 'Bubba', 'email' => '*****@*****.**')); $curl->execute(); echo $curl->getBody(); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
/** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->buildRequest(); $url = ($this->testMode ? $this->testUrl : $this->liveUrl) . rawurlencode($this->request); $options = array(CURLOPT_HEADER => false); if (!$verifyPeer) { $options[CURLOPT_SSL_VERIFYPEER] = false; } $curl = new Curl($url, $options); $curl->execute(); $this->response = simplexml_load_string($curl->getBody()); if (isset($this->response->Package)) { $this->responseCode = 1; foreach ($this->response->Package->Postage as $rate) { $this->rates[str_replace(array('<', '>'), array('<', '>'), (string) $rate->MailService)] = (string) $rate->Rate; } $this->rates = array_reverse($this->rates, true); } else { if (isset($this->response->Number)) { $this->responseCode = (string) $this->response->Number; $this->responseMessage = (string) $this->response->Description; } else { $this->responseCode = 0; } } }
public function testHeadersAndBody() { $c = new Curl('http://www.popphp.org/version', array(CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true)); $c->execute(); $this->assertEquals('text/plain', $c->getHeader('Content-Type')); $this->assertGreaterThan(1, count($c->getHeaders())); $this->assertContains('HTTP', $c->getRawHeader()); $this->assertEquals('1.7.0', $c->getBody()); $this->assertEquals('200', $c->getCode()); $this->assertEquals('1.1', $c->getHttpVersion()); $this->assertEquals('OK', $c->getMessage()); }