KEMBAR78
WP HTTP API | PDF
WP HTTP API Eunus Hosen! 
Co-Founder & CTO! 
DevsTeam
What is HTTP API
Why HTTP API 
❖ cURL : A library to communicate with remote hosts. Works only 
when the cURL extension is loaded into PHP.! 
❖ File system (fopen, file_get_contents) : This function opens up a file 
or an URL and this works when php ini_settings allows for this.! 
❖ Sockets (fsockopen) : Initiates a socket connection to the resource 
specified by host-name. Again it’s possible that the hosting company 
might have disabled the fsockopen function.! 
❖ Streams: Works on PHP 4.3 or later.! 
❖ HTTP: Provides a powerful request and parallel interface for remote 
calls. It needs PHP 5.2+
WP_HTTP Class
Helper Functions 
❖ wp_remote_get() - Retrieves a URL using the GET HTTP 
method.! 
❖ wp_remote_post() - Retrieves a URL using the POST HTTP 
method.! 
❖ wp_remote_head() - Retrieves a URL using the HEAD 
HTTP method.! 
❖ wp_remote_request() - Retrieves a URL using either the 
default GET or a custom HTTP method (should be caps) 
that you specify.
An Example
Response
Retrieve Body: wp_remote_retrieve_body($response)
Retrieve Body: wp_remote_retrieve_headers($response)
More Helper Functions 
❖ wp_remote_retrieve_body() - Retrieves just the body from the response.! 
❖ wp_remote_retrieve_header() - Gives you a single HTTP header based 
on name from the response.! 
❖ wp_remote_retrieve_headers() - Returns all of the HTTP headers in an 
array for processing.! 
❖ wp_remote_retrieve_response_code() - Gives you the number for the 
HTTP response. This should be 200, but could be 4xx or even 3xx on 
failure.! 
❖ wp_remote_retrieve_response_message() - Returns the response 
message based on the response code
Resources 
❖ wp_remote_get: http://codex.wordpress.org/Function_Reference/wp_remote_get! 
❖ wp_remote_post: http://codex.wordpress.org/Function_Reference/wp_remote_post! 
❖ wp_remote_head: http://codex.wordpress.org/Function_Reference/wp_remote_head! 
❖ wp_remote_retrieve_body : http://codex.wordpress.org/Function_Reference/ 
wp_remote_retrieve_body! 
❖ wp_remote_retrieve_headers : http://codex.wordpress.org/Function_Reference/ 
wp_remote_retrieve_headers! 
❖ wp_remote_retrieve_header: http://codex.wordpress.org/Function_Reference/ 
wp_remote_retrieve_header! 
❖ wp_remote_retrieve_response_code : http://codex.wordpress.org/Function_Reference/ 
wp_remote_retrieve_response_code! 
❖ wp_remote_retrieve_response_message : http://codex.wordpress.org/Function_Reference/ 
wp_remote_retrieve_response_message
Got a Question?
Thank you!

WP HTTP API

  • 1.
    WP HTTP APIEunus Hosen! Co-Founder & CTO! DevsTeam
  • 2.
  • 3.
    Why HTTP API ❖ cURL : A library to communicate with remote hosts. Works only when the cURL extension is loaded into PHP.! ❖ File system (fopen, file_get_contents) : This function opens up a file or an URL and this works when php ini_settings allows for this.! ❖ Sockets (fsockopen) : Initiates a socket connection to the resource specified by host-name. Again it’s possible that the hosting company might have disabled the fsockopen function.! ❖ Streams: Works on PHP 4.3 or later.! ❖ HTTP: Provides a powerful request and parallel interface for remote calls. It needs PHP 5.2+
  • 4.
  • 5.
    Helper Functions ❖wp_remote_get() - Retrieves a URL using the GET HTTP method.! ❖ wp_remote_post() - Retrieves a URL using the POST HTTP method.! ❖ wp_remote_head() - Retrieves a URL using the HEAD HTTP method.! ❖ wp_remote_request() - Retrieves a URL using either the default GET or a custom HTTP method (should be caps) that you specify.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
    More Helper Functions ❖ wp_remote_retrieve_body() - Retrieves just the body from the response.! ❖ wp_remote_retrieve_header() - Gives you a single HTTP header based on name from the response.! ❖ wp_remote_retrieve_headers() - Returns all of the HTTP headers in an array for processing.! ❖ wp_remote_retrieve_response_code() - Gives you the number for the HTTP response. This should be 200, but could be 4xx or even 3xx on failure.! ❖ wp_remote_retrieve_response_message() - Returns the response message based on the response code
  • 11.
    Resources ❖ wp_remote_get:http://codex.wordpress.org/Function_Reference/wp_remote_get! ❖ wp_remote_post: http://codex.wordpress.org/Function_Reference/wp_remote_post! ❖ wp_remote_head: http://codex.wordpress.org/Function_Reference/wp_remote_head! ❖ wp_remote_retrieve_body : http://codex.wordpress.org/Function_Reference/ wp_remote_retrieve_body! ❖ wp_remote_retrieve_headers : http://codex.wordpress.org/Function_Reference/ wp_remote_retrieve_headers! ❖ wp_remote_retrieve_header: http://codex.wordpress.org/Function_Reference/ wp_remote_retrieve_header! ❖ wp_remote_retrieve_response_code : http://codex.wordpress.org/Function_Reference/ wp_remote_retrieve_response_code! ❖ wp_remote_retrieve_response_message : http://codex.wordpress.org/Function_Reference/ wp_remote_retrieve_response_message
  • 12.
  • 13.