Why do I get a blank response when I send a post request to a url?

I have been struggling mightily over what is probably a simple question. The web is filled with Curl examples that show how to post something to another script and get a response. I've tried lots of variations and can't get anything back on the response. The response does not include any data and does not include any curl error information. I've tried to boil this down to a very simple scenario which I've demonstrated in the two scripts below. Both scripts run on the same server. The first initiates a post request to send a simple xml string and the second is simply echoing something back.

The next assumption is that $_post is the correct variable name, that it is defined, not empty, and can be printed by print_r(). None of these statements are true. The correct variable name is $_POST. The reason all of this escaped your test is that the default error reporting level for PHP suppresses Notice messages, and an undefined variable is not an error in PHP -- it only rises to the level of a Notice. You can change this behavior by setting error_reporting(E_ALL). And when you are trying to debug software, you want to see all the errors.

The last assumption that seems to have problematic potential is the assumption that the POST method will actually return anything within the time limit. It might not. POST is a method that allows the target script to run asynchronously. It is perfectly acceptable to start a script with POST and never wait for it to complete.

Here is how I would re-write test2.php for the initial tests. Once you got that to work, then you could go back and start adding in the XML tags.

HTH, ~Ray

<?php // test2.php// SET THE RIGHT ERROR REPORTING FOR DEVELOPMENT AND DEBUGGINGerror_reporting(E_ALL);// START THE OUTPUT BUFFERS ob_start();// GUARANTEE SOME OUTPUT - DELETE THIS AFTER THE FIRST SUCCESSFUL TESTecho "HELLO WORLD";// DUMP THE POST ARRAY INTO THE OUTPUT BUFFERprint_r($_POST);// COLLECT THE BUFFER AND ECHO IT INTO THE BROWSER OUTPUT STREAM$ob = ob_get_clean();echo $ob;die();

Thanks to everyone. I know that $_post doesn't equal $_POST. I guess I was getting so caught up in how to format the CURL options and whether to use headers or not, that I didn't pay much attention to test2.php.

Just a thought for going forward. If you use $_REQUEST instead of $_POST, you can test by adding arguments to your URL string. $_REQUEST contains both POST and GET variables. With a strategy like that you would have been able to verify that test2.php was working before you relied on it to test your other script.