AtD_http_post

Returns array with headers in $response[0] and body in $response[1] Based on a function from Akismet.

Description

AtD_http_post( $request, $host, $path, (int) $port = 80 ); 

Parameters (4)

0. $request
The request.
1. $host
The host.
2. $path
The path.
3. $port — Optional. (int) => 80
The port.

Usage

  1. if ( !function_exists( 'AtD_http_post' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/after-the-deadline/proxy.php'; 
  3.  
  4. // The request. 
  5. $request = null; 
  6.  
  7. // The host. 
  8. $host = null; 
  9.  
  10. // The path. 
  11. $path = null; 
  12.  
  13. // The port. 
  14. $port = 80; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = AtD_http_post($request, $host, $path, $port); 
  18.  

Defined (1)

The function is defined in the following location(s).

/modules/after-the-deadline/proxy.php  
  1. function AtD_http_post( $request, $host, $path, $port = 80 ) { 
  2. $http_args = array( 
  3. 'body' => $request,  
  4. 'headers' => array( 
  5. 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),  
  6. 'Host' => $host,  
  7. 'User-Agent' => 'AtD/0.1' 
  8. ),  
  9. 'httpversion' => '1.0',  
  10. /** 
  11. * Change the timeout time for AtD post. 
  12. * @module after-the-deadline 
  13. * @since 1.2.3 
  14. * @param int $var Timeout time in seconds, default 15. 
  15. */ 
  16. 'timeout' => apply_filters( 'atd_http_post_timeout', 15 ),  
  17. ); 
  18.  
  19. // Handle non-standard ports being passed in. 
  20. if ( ( 80 !== $port ) && is_numeric( $port ) && ( intval( $port ) > 0 ) ) { 
  21. $host .= ':' . intval( $port ); 
  22. // Strip any / off the begining so we can add it back and protect against SSRF 
  23. $path = ltrim( $path, '/' ); 
  24. $AtD_url = set_url_scheme( "http://{$host}/{$path}" ); 
  25. $response = wp_remote_post( $AtD_url, $http_args ); 
  26. $code = (int) wp_remote_retrieve_response_code( $response ); 
  27.  
  28. if ( is_wp_error( $response ) ) { 
  29. /** 
  30. * Fires when there is a posterrorto AtD. 
  31. * @module after-the-deadline 
  32. * @since 1.2.3 
  33. * @param int|string http-error Theerrorthat AtD runs into. 
  34. */ 
  35. do_action( 'atd_http_post_error', 'http-error' ); 
  36. return array(); 
  37. } elseif ( 200 != $code ) { 
  38. /** This action is documented in modules/after-the-deadline/proxy.php */ 
  39. do_action( 'atd_http_post_error', $code ); 
  40.  
  41. return array( 
  42. wp_remote_retrieve_headers( $response ),  
  43. wp_remote_retrieve_body( $response ),  
  44. );