- Wednesday, January 21, 2009
- Make a Post Request through PHP Script
- Making a GET Request through PHP is very easy, you can treat the URL of the target page as a file, open it using fopen while include the parameters in the URL String:
$result = file_get_contents("www.example.com?param1=value1¶m2=value2");
But some times GET does not work, specially when you need to communicate with other platforms "other servers" which already written and expect a POST request.
Making a Post Request is Easy to, but it is a little tricky, because in POST requests you can not add the paramters to the end of the URL as in GET, instead you need to send them in the HTTP headers, and in order to do that, you need to open a socket using fsocketopen and send all the HTTP headers that the target server expect:
function PostRequest($url, $referer, $_data) {
// convert variables array to string:
$data = array();
while(list -