$value) { $fieldstring .= '"' . $key .'"'.':'.'"'.$value.'"'.','; } $fieldstring=substr($fieldstring,0,-1); $postfields = '{"document" : { '. $fieldstring .'}, "safe" : true }'; //echo($postfields .'
'); // send request to the service using curl - http://us2.php.net/curl $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL, $request); // set url to post to - must match above curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // HTTP method curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); // HTTP entity body curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( // set HTTP header fields 'Content-Type: application/json', 'Content-Length: ' . strlen($postfields)) // HTTP headers ); if(curl_exec($ch) === false) // run the whole process with error handling { echo 'Curl error: ' . curl_error($ch) . '
'; } else { echo 'Operation completed without any errors. Return to home.'; } curl_close($ch); // close connection ?>