Last active
August 29, 2015 14:11
-
-
Save xuqingfeng/50520e0b2a8246a25e12 to your computer and use it in GitHub Desktop.
curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Perform the CURL query | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, "php-trello/$this->version"); | |
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | |
``` | |
// Perform the CURL query | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, "php-trello/$this->version"); | |
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | |
switch ($method) { | |
case 'GET': | |
break; | |
case 'POST': | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($restData, '', '&')); | |
$restData = array(); | |
break; | |
case 'PUT': | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($restData, '', '&')); | |
$restData = array(); | |
break; | |
case 'DELETE': | |
case 'DEL': | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); | |
break; | |
default: | |
throw new \Exception('Invalid method specified'); | |
break; | |
} | |
$url = $this->buildRequestUrl($method, $path, $restData); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
// Grab the response from Trello | |
$responseBody = curl_exec($ch); | |
if (!$responseBody) { | |
// If there was a CURL error of some sort, log it and |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment