/** * @brief GET a resource * * Make the HTTP GET call to retrieve the record pointed to by the URL. * * @param url URL of resource * * @result Contents of resource */ function get($url, $userAgent = '', $timeout = 0) { global $config; $data = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt ($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); if ($userAgent != '') { curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); } if ($timeout != 0) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } if ($config['proxy_name'] != '') { curl_setopt($ch, CURLOPT_PROXY, $config['proxy_name'] . ':' . $config['proxy_port']); } $curl_result = curl_exec($ch); //echo $curl_result; if (curl_errno($ch) != 0) { echo "CURL error: ", curl_errno($ch), " ", curl_error($ch); } else { $info = curl_getinfo($ch); //$header = substr($curl_result, 0, $info['header_size']); //echo $header; $http_code = $info['http_code']; //echo "<p><b>HTTP code=$http_code</b></p>"; if (HttpCodeValid($http_code)) { $data = $curl_result; } } return $data; }
function post($url, $postfields) { global $config; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); if ($config['proxy_name'] != '') { curl_setopt($ch, CURLOPT_PROXY, $config['proxy_name'] . ':' . $config['proxy_port']); } $html = ''; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields)); $curl_result = curl_exec($ch); //echo $curl_result; if (curl_errno($ch) != 0) { echo "CURL error: ", curl_errno($ch), " ", curl_error($ch); } else { $info = curl_getinfo($ch); $http_code = $info['http_code']; if (HttpCodeValid($http_code)) { $html = $curl_result; } } return $html; }
function ResolveGuid($guid) { global $config; $url = 'http://bioguid.info/' . $guid; $data = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Tell resolver we want RDF $request_header = array(); array_push($request_header, 'Accept: application/rdf+xml'); curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header); if ($config['proxy_name'] != '') { curl_setopt($ch, CURLOPT_PROXY, $config['proxy_name'] . ':' . $config['proxy_port']); } $curl_result = curl_exec($ch); if (curl_errno($ch) != 0) { echo "CURL error: ", curl_errno($ch), " ", curl_error($ch); } else { $info = curl_getinfo($ch); $http_code = $info['http_code']; if (HttpCodeValid($http_code)) { $data = $curl_result; } } return $data; }
/** * @brief GET a resource * * Make the HTTP GET call to retrieve the record pointed to by the URL. * * @param url URL of resource * * @result Contents of resource */ function get($url, $userAgent = '', $content_type = '') { global $config; $data = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); // timeout (seconds) curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); if ($userAgent != '') { curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); } if ($config['proxy_name'] != '') { curl_setopt($ch, CURLOPT_PROXY, $config['proxy_name'] . ':' . $config['proxy_port']); } if ($content_type != '') { curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: " . $content_type)); } $curl_result = curl_exec($ch); if (curl_errno($ch) != 0) { echo "CURL error: ", curl_errno($ch), " ", curl_error($ch); } else { $info = curl_getinfo($ch); //print_r($info); $header = substr($curl_result, 0, $info['header_size']); //echo $header; $http_code = $info['http_code']; //echo "HTTP code=$http_code\n"; if (HttpCodeValid($http_code)) { $data = substr($curl_result, $info['header_size']); //$data = $curl_result; } } return $data; }