philpot
03-16-2007, 11:39 AM
Hi
I need to perform a HTTP POST from a PHP script. Essentially my PHP script is receiving form data and making sure it is complete and valid before submitting it to another site.
I have used CURL and the streams layer to sucessfully make the POST from PHP, but they act as clients, whereas what I want to do is emulate a true browser form submission by issuing the correct HTTP headers. Here is what I have so far:
<?php
$post_data = 'var1=123&var2=456';
$content_length = strlen($post_data);
header('POST /test/test.php HTTP/1.1');
header('Host: localhost');
header('Connection: close');
header('Content-type: application/x-www-form-urlencoded');
header('Content-length: ' . $content_length);
header('');
header($post_data);
exit();
?>
At the moment, this causes Apache to throw an internal error. I have tested the same code on IIS with the same result. I have also tested the script with PHP 4 & 5 - again same result.
I have even simplified the script to perform a GET:
<?php
header('GET /test/test.php HTTP/1.1');
header('Host: localhost');
exit();
?>
This too causes a server error.
What in the blazes am I doing wrong?
I need to perform a HTTP POST from a PHP script. Essentially my PHP script is receiving form data and making sure it is complete and valid before submitting it to another site.
I have used CURL and the streams layer to sucessfully make the POST from PHP, but they act as clients, whereas what I want to do is emulate a true browser form submission by issuing the correct HTTP headers. Here is what I have so far:
<?php
$post_data = 'var1=123&var2=456';
$content_length = strlen($post_data);
header('POST /test/test.php HTTP/1.1');
header('Host: localhost');
header('Connection: close');
header('Content-type: application/x-www-form-urlencoded');
header('Content-length: ' . $content_length);
header('');
header($post_data);
exit();
?>
At the moment, this causes Apache to throw an internal error. I have tested the same code on IIS with the same result. I have also tested the script with PHP 4 & 5 - again same result.
I have even simplified the script to perform a GET:
<?php
header('GET /test/test.php HTTP/1.1');
header('Host: localhost');
exit();
?>
This too causes a server error.
What in the blazes am I doing wrong?