Overview

Namespaces

  • None
  • PHP

Classes

  • RESTian
  • RESTian_Application_Json_Parser
  • RESTian_Application_Serialized_Php_Parser
  • RESTian_Application_Xml_Parser
  • RESTian_Auth_Provider_Base
  • RESTian_Base
  • RESTian_Basic_Http_Auth_Provider
  • RESTian_Client
  • RESTian_Http_Agent_Base
  • RESTian_Not_Applicable_Provider
  • RESTian_Parser_Base
  • RESTian_Php_Curl_Http_Agent
  • RESTian_Request
  • RESTian_Response
  • RESTian_Service
  • RESTian_Settings
  • RESTian_Text_Csv_Parser
  • RESTian_Text_Html_Parser
  • RESTian_Text_Plain_Parser
  • RESTian_Var
  • RESTian_WordPress_Http_Agent
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 1: <?php
 2: // @todo Need to support POST, PUT, DELETE
 3: /**
 4:  * An HTTP Agent for RESTian that uses PHP's CURL to make HTTP requests.
 5:  */
 6: class RESTian_Php_Curl_Http_Agent extends RESTian_Http_Agent_Base {
 7:   /**
 8:    * Makes an HTTP request using PHP's CURL
 9:    *
10:    * @param RESTian_Request $request
11:    * @param RESTian_Response $response
12:    * @return RESTian_Response
13:    */
14:   function make_request( $request, $response ) {
15: 
16:     $ch = curl_init();
17: 
18:     curl_setopt_array(
19:       $ch, array(
20:         CURLOPT_URL => $request->get_url(),
21:         CURLOPT_USERAGENT => $request->client->get_user_agent(),
22:         CURLOPT_HTTPHEADER => $request->get_curl_headers(),
23:         CURLOPT_POST => false,
24:         CURLOPT_HEADER => false,
25:         CURLOPT_TIMEOUT => '30',
26:         CURLOPT_RETURNTRANSFER => true,
27:         CURLOPT_SSL_VERIFYPEER => $request->sslverify,
28:         CURLOPT_SSL_VERIFYHOST => ( true === $request->sslverify ) ? 2 : false,
29:     ));
30:     if ( ! $request->omit_body ) {
31:       $response->body = trim( curl_exec( $ch ) );
32:     }
33: 
34:     $info = curl_getinfo($ch);
35:     $response->status_code = $info['http_code'];
36: 
37:     if ( 0 != curl_errno( $ch ) )
38:       $response->set_http_error( curl_errno( $ch ), curl_error( $ch ) );
39: 
40:     if ( ! $request->omit_result ) {
41:       $response->result = (object)array(
42:         'info' => $info,
43:         'version' => curl_version(),
44:         'error' => curl_error( $ch ),
45:         'errno' => curl_errno( $ch ),
46:       );
47:     }
48:     curl_close($ch);
49: 
50:     return $response;
51:   }
52: 
53: }
54: 
55: 
API documentation generated by ApiGen 2.8.0