Skip to content

Instantly share code, notes, and snippets.

@xuqingfeng
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuqingfeng/50520e0b2a8246a25e12 to your computer and use it in GitHub Desktop.
Save xuqingfeng/50520e0b2a8246a25e12 to your computer and use it in GitHub Desktop.
curl
<?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