Search Webmaster Help and Solution

Technical POST Question

I created a file to POST data to a Drupal RESTful API, but for some reason Drupal doesnt 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 Im 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:
PHP Code: $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 Im missing. Im just not sure what... I created a file to POST data to a Drupal RESTful API, but for some reason Drupal doesnt 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 Im 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:
PHP Code: $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 Im missing. Im just not sure what...

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).