Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- make an http POST request and return the response content and headers
- @param string $url url of the requested script
- @param array $data hash array of request variables
- @return returns a hash array with response content and headers in the following form:
- array ('content'=>'<html></html>'
- , 'headers'=>array ('HTTP/1.1 200 OK', 'Connection: close', ...)
- )
- */
- function http_post ($url, $data)
- {
- $data_url = http_build_query ($data);
- $data_len = strlen ($data_url);
- return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'POST'
- , 'header'=>"Connection: close\r\nContent-Length: $data_len\r\n"
- , 'content'=>$data_url
- ))))
- , 'headers'=>$http_response_header
- );
- }
- ?>
Add Comment
Please, Sign In to add comment