Guest User

Untitled

a guest
Jan 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. /**
  3. make an http POST request and return the response content and headers
  4. @param string $url    url of the requested script
  5. @param array $data    hash array of request variables
  6. @return returns a hash array with response content and headers in the following form:
  7.     array ('content'=>'<html></html>'
  8.         , 'headers'=>array ('HTTP/1.1 200 OK', 'Connection: close', ...)
  9.         )
  10. */
  11. function http_post ($url, $data)
  12. {
  13.     $data_url = http_build_query ($data);
  14.     $data_len = strlen ($data_url);
  15.  
  16.     return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'POST'
  17.             , 'header'=>"Connection: close\r\nContent-Length: $data_len\r\n"
  18.             , 'content'=>$data_url
  19.             ))))
  20.         , 'headers'=>$http_response_header
  21.         );
  22. }
  23. ?>
Add Comment
Please, Sign In to add comment