public function test_getLastErrorMessage() { $this->curl->setOption(CURLOPT_URL, 'foo://bar'); $this->curl->setOption(CURLOPT_RETURNTRANSFER, TRUE); $this->curl->execute(); $this->assertEquals($this->curl->getLastErrorMessage(), 'cURL failed with error #1: Protocol foo not supported or disabled in libcurl'); }
public static function lookup($location_string) { $api = 'http://maps.googleapis.com/maps/api/geocode/json'; $api_call = new CurlRequest($api); $api_call->setParams(array('sensor' => 'false', 'address' => $location_string)); try { $result = $api_call->execute(); $geocode = json_decode($result['body']); if ($geocode->status != 'OK') { return false; } return $geocode->results[0]->geometry->location; } catch (Exception $e) { return false; } }
public function getSign() { $noncestr = Input::get('noncestr', ''); $timestamp = Input::get('timestamp', ''); $url = Input::get('url', ''); try { $curl = new CurlRequest(); $request_url = 'http://qnckwx.54qnck.com/GetjsapiInfo.ashx?noncestr=' . $noncestr . '×tamp=' . $timestamp . '&url=' . urlencode($url); $data = $curl->get($request_url); $data = $data['content']; $re = Tools::reTrue('获取签名成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getMessage(), '获取签名失败:' . $e->getMessage()); } return Response::json($re); }
public function execute($response = null) { // note: $response is not used here, only needed to keep PHP strict mode // happy. $this->prepare(); $response = parent::execute(new TransloaditResponse()); $response->parseJson(); return $response; }
/** * Fetches data from the Blizzard Diablo 3 API * * @param string $url * @return mixed */ protected function getData($url) { // set curl options $this->request = new CurlRequest($url); $this->request->setOption(CURLOPT_URL, $url); $this->request->setOption(CURLOPT_RETURNTRANSFER, true); $this->request->setOption(CURLOPT_CONNECTTIMEOUT, 5); $this->request->setOption(CURLOPT_TIMEOUT, 30); $this->request->setOption(CURLOPT_MAXREDIRS, 7); $this->request->setOption(CURLOPT_HEADER, false); return $this->request->execute(); }
/** * Connect to the proxy. * * @param string $url is the full URL containing the hostname and request. * @param string $host is the hostname of the new site used in the Host: HTTP header. * @param string $method is the HTTP method (GET | POST). * @param string $post_params are the POST arguments in key=value&key=value format. * * @return array containing HTTP response code, the body of the response, elapsed time. */ static function surf($post_params) { try { $mych = new CurlRequest(); $params = array('url' => 'http://localhost/proxy/easypress-console-proxy.php', 'host' => 'console.easypress.ca', 'header' => '', 'method' => 'POST', 'referer' => '', 'cookie' => '', 'post_fields' => $post_params, 'timeout' => 90, 'verbose' => 0); $mych->init($params); $result = $mych->exec(); if ($result['curl_error']) { throw new Exception($result['curl_error']); } if ($result['http_code'] != '200') { throw new Exception("HTTP Code = " . $result['http_code'] . "\nBody: " . $result['body']); } if (NULL === $result['body']) { throw new Exception("Body of file is empty"); } //echo $result['header']; //echo 'HTTP return code: ' . $result['http_code']; } catch (Exception $e) { error_log("easypress-console::surf(): " . $e->getMessage()); } return array('code' => $result['http_code'], 'body' => $result['body'], 'etime' => $result['etime']); }
preg_match($rgx_UrlPattern, $str_RequestURL, $arr_ParsedPath); $str_ServerURL = $arr_ParsedPath[1]; $str_Entity = $arr_ParsedPath[2]; $int_ID = $arr_ParsedPath[3]; $str_Method = $arr_ParsedPath[4]; // Get the request body if the requets method is POST and rewrite it if ($str_RequestMethod == 'POST') { $str_RequestBody = file_get_contents('php://input'); $arr_RedirectFields = array('ID' => $int_ID != '' ? $int_ID : NULL, 'method' => $str_Method, 'data' => $str_RequestBody); } elseif ($str_RequestMethod == 'GET') { $arr_RedirectFields = $int_ID != '' ? array('ID' => $int_ID) : array(); $arr_RedirectFields = array_merge($arr_RedirectFields, $_GET); } // Redirect the request $str_RedirectUrl = $str_ServerName . $str_ServerURL . '/rest-api/controllers/' . $str_Entity . '.php'; $obj_Curl = new CurlRequest(); $obj_Curl->setCookie('GawainSessionID', $str_SessionID); $obj_Curl->setCookie('GawainUser', $str_User); $obj_Curl->setCookie('GawainClientIP', $_SERVER['REMOTE_ADDR']); if ($str_RequestMethod == 'GET') { $obj_Curl->get($str_RedirectUrl, $arr_RedirectFields); } elseif ($str_RequestMethod == 'POST') { $obj_Curl->post($str_RedirectUrl, $arr_RedirectFields); } if ($obj_Curl->error) { echo 'Error ' . $obj_Curl->error_code . ': ' . $obj_Curl->error_message; } else { switch ($obj_Curl->http_status_code) { case 200: $arr_ResponseHeader = explode(PHP_EOL, trim($obj_Curl->raw_response_headers)); foreach ($arr_ResponseHeader as $str_ResponseHeader) {
function stori_es_validate_apikey_callback() { global $HttpHeaders; if (isset($_POST['api_key']) && stori_es_validate_apiurl_callback(true) == STORI_ES_API_SUCCESS) { $lHttpHeaders = $HttpHeaders; $lHttpHeaders[1] = 'Authorization: BASIC ' . $_POST['api_key']; $api_url = stori_es_correct_api_url($_POST['api_url']); // GET /users/self JSON to confirm API access $CurlRequest = new CurlRequest(); $CurlRequest->setHttpHeaders($lHttpHeaders); $CurlRequest->createCurl($api_url . 'users/self'); $objUser = json_decode($CurlRequest->getContent()); echo $objUser->meta->status; // return value to ajax script } else { echo STORI_ES_API_INVALID; } wp_die(); }
public function __construct($url) { echo "Requesting {$url}\n"; parent::__construct($url); }
#!/usr/bin/php -q <?php include 'classes/CurlRequest.php'; $options = array(CURLOPT_URL => "http://posttestserver.com/post.php", CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array("Key1" => "Value1", "Key2" => "Value2")); $test = new CurlRequest($options); foreach ($options as $option => $value) { $test->ch_setopt($option, $value); } $test->ch_exec(); $test->ch_close(); echo $test->get_code() . chr(10) . $test->get_header() . chr(10);
/** * HTTP requests * * @param array $request should minimally contain the POST arguments. * @return array containing HTTP response code, the body of the response, elapsed time. */ public function http_req($request = array()) { global $params; $host = 'provision.boreal321.com'; if ($params['location'] == 'equalit.ie') { $host = 'eqpress.equalit.ie'; } $url = 'https://' . $host . '/pwpush/pwpusher_public/pw.php'; $response = array(); $defaults = array('url' => $url, 'host' => $host, 'method' => 'POST', 'timeout' => 30, 'verbose' => 0); $request = array_merge($defaults, $request); try { $mych = new CurlRequest(); $mych->init($request); $response = $mych->exec(); if ($response['curl_error']) { throw new Exception($response['curl_error']); } //if ( $response['http_code'] != '200' ) throw new Exception( "HTTP Code = " . $response['http_code'] . '\nBody: ' . $response['body'] ); if (NULL === $response['body']) { throw new Exception("Body of response is empty"); } } catch (Exception $e) { $this->process_errors("http_req error: " . $e->getMessage() . "\n" . print_r($response, true)); } //return array( 'code' => $response['http_code'], 'body' => $response['body'], 'etime' => $response['etime'] ); //return $response['body']; return $response; }
public function prepareResponse(array $options, $response, $headerLength) { return parent::prepareResponse($options, $response, $headerLength); }
<p>用户 ID: <input type="text" name="user_id" style="width: 300px" /></p> <p>Session Key: <input type="text" name="session_key" style="width: 300px" /></p> <p>json 数据: <input type="text" name="json_request" style="width: 300px" /></p> <p><input type="submit" value="API接口测试" /></p> </form> <?php require_once '../libs/common/curl/CurlRequest.class.php'; require_once '../libs/common/curl/CurlResponse.class.php'; $api_name = @$_POST['api_name']; $user_id = @$_POST['user_id']; $session_key = @$_POST['session_key']; $json_request = @$_POST['json_request']; //echo $api_name; if (!empty($api_name)) { $request = new CurlRequest('http://192.168.18.31/y_game/api.php/' . trim($api_name)); $postDate = 'user_id=' . $user_id . '&session_key=' . $session_key . '&json_request=' . $json_request . ''; $response = $request->httpPost($postDate); $error = ""; echo "<hr />"; echo "请求API接口:" . $api_name; echo "<br />"; echo "请求参数:" . $postDate; echo "<br />"; echo "<br />"; echo "<br />"; echo "API 处理结果:"; if ($response->getStatus() != 200) { $error = "状态code: " . $response->getStatus(); echo "error:" . $error; }
/** * Connect to the proxy. * * @param string $url is the full URL containing the hostname and request. * @param string $host is the hostname of the new site used in the Host: HTTP header. * @param string $method is the HTTP method (GET | POST). * @param string $post_params are the POST arguments in key=value&key=value format. * * @return array containing HTTP response code, the body of the response, elapsed time. */ function surf($post_params) { require_once dirname(__FILE__) . '/../plugin/easypress-console/inc/class-curl-request.php'; try { $mych = new CurlRequest(); $params = array('url' => 'https://www.getpendeo.com/pwpush/pwpusher_public/pw.php', 'host' => 'www.getpendeo.com', 'header' => '', 'method' => 'POST', 'referer' => '', 'cookie' => '', 'post_fields' => $post_params, 'timeout' => 90, 'verbose' => 0); $mych->init($params); $result = $mych->exec(); if ($result['curl_error']) { throw new Exception($result['curl_error']); } if ($result['http_code'] != '200') { throw new Exception("HTTP Code = " . $result['http_code'] . "\nBody: " . $result['body']); } if (NULL === $result['body']) { throw new Exception("Body of file is empty"); } //echo $result['header']; //echo 'HTTP return code: ' . $result['http_code']; } catch (Exception $e) { error_log("easypress-console-proxy: surf() error. " . $e->getMessage()); } return array('code' => $result['http_code'], 'body' => $result['body'], 'etime' => $result['etime']); }
function __request (&$object_or_class, $method, $path, $data = null, $headers = null) { if (is_null($headers)) { $headers = array( 'Accept: application/xml', 'Content-Type: application/xml' ); } $request = new CurlRequest(); $request->headers = $headers; $request->url = $this->url . $object_or_class->interpolated_uri() . $path; $request->username = $this->username; $request->password = $this->password; $request->set(CURLOPT_CUSTOMREQUEST, $method); $request->set(CURLOPT_SSL_VERIFYPEER, false); if (!empty($data)) $request->set(CURLOPT_POSTFIELDS, $data); $response = $request->execute(); return $response; }