I created a file to POST data to a Drupal RESTful API, but for some reason Drupal doesn't see the POST come in. When I send the data via http GET, POST, or DELETE to my sample RESTful API that I wrote for testing, the data comes in just fine. If I were to make a simple HTML form and POST, Drupal records the POST without incident. I suspect it is somehow in the way I'm forming my POST request, but I need some guidance on how to procede.
How do I look at a complete POST request coming from a web form? Not just the POST variables and their values, but all the header information and anything else that is streamed in? Does a html form POST data differently than say using file_get_contents($url, false, $context)?
Here is the code I currently run to POST data to the site:
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
// the next line had to have a lot of altering, as the http_build_query() function mangled
// both the keys and the data. str_replace() fixed the keys and urldecode() fixed the data
'content' => urldecode(str_replace('&','&',http_build_query($post_data_keyed_array))),
'ignore_errors' => true
)
);
//stream encode the data
$context = stream_context_create($opts);
//push the data via POST to the API site...
$result = file_get_contents("$API_URL", false, $context);
My sample API handles the POST request without a hitch. I suspect there is something in a normal html web form POST that is being passed that I'm missing. I'm just not sure what...