From 624bfae9d772d00b0f448ea5ad0f140ab6240f6a Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 21 Sep 2015 11:00:02 +0100 Subject: [PATCH 1/2] store the last response in the api - in a similar way to how lastRequest() is already fix minor typo in doc add explicit curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); --- namecheap_api.php | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/namecheap_api.php b/namecheap_api.php index a3c301a..3f3c6ea 100644 --- a/namecheap_api.php +++ b/namecheap_api.php @@ -42,7 +42,12 @@ class NamecheapApi { * @var array An array representing the last request made */ private $last_request = array('url' => null, 'args' => null); - + + /** + * @var array An array representing the last response back from + */ + private $last_response = array( 'url' => null, 'http_status' => null, 'response' => null, 'error' => null); + /** * Sets the connection details * @@ -95,22 +100,46 @@ public function submit($command, array $args = array()) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args)); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); $response = curl_exec($ch); + + $info = curl_getinfo($ch); + + $last_response = array( + 'error' => curl_error($ch), + 'url' => $url, + 'http_status' => $info['http_code'], + 'response' => $response + ); + curl_close($ch); - + $this->last_response = $last_response; + return new NamecheapResponse($response); } /** * Returns the details of the last request made * - * @return array An array containg: + * @return array An array containing: * - url The URL of the last request * - args The paramters passed to the URL */ public function lastRequest() { return $this->last_request; } + + /** + * Returns the details of the last response. + * + * @return array An array containing: + * - url - the URL requested + * - error - any curl related error. + * - http_status - http status code (e.g. 200) + * - response - the raw textual response + */ + public function lastResponse() { + return $this->last_response; + } } ?> From bb4a8f5483938f0308117a2e0868803acff9b94f Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 25 Sep 2015 17:27:48 +0100 Subject: [PATCH 2/2] Follow redirects - namecheap seem to do this when everything breaks - e.g redirect to /PredefinedResponses/500-UnhandledException.xml?aspxerrorpath=/xml.response - otherwise we do not get XML back --- namecheap_api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/namecheap_api.php b/namecheap_api.php index 3f3c6ea..2cc11d5 100644 --- a/namecheap_api.php +++ b/namecheap_api.php @@ -100,6 +100,7 @@ public function submit($command, array $args = array()) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args)); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); $response = curl_exec($ch);