Problem: I receive a 501 not implemented error when attempting a POST
request. The GET
method works just fine, but its data length limit makes it nonviable for the XML
string I wish to pass in to the PHP script.
Background: I'm generating an XML string based on some user inputs with JavaScript. Next, I'm trying to pass this XML
string (after encoding it) to a PHP script to write the string as an XML
file on the server and execute a command regarding it.
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
JS:
$.ajax({
type: "POST",
url: 'Submit_Job_to_Computer_Cluster.php',
data:
{
XML_requested_job: XML_String
},
dataType: "text",
success: function(msg)
{
console.log(msg);
alert("success");
},
error: function(xhr, ajaxOptions, thrownError)
{
console.log(xhr.status);
alert(xhr.responseText);
alert(thrownError);
}
});
}
PHP (5.4.16):
<?php
switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://from.com': case 'https://from.com':
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
break;
}
$XML_string = $_POST["XML_requested_job"]; //passed in string
try{
$XML_file= "workflowPROD.xml";
$file_handle = fopen($XML_file, 'w') or die("Can't open the file");
fwrite($file_handle, $XML_string);
fclose($file_handle);
} catch (Exception $e) {
}
$today = getdate();
$year = (string) $today['year'];
$month = (string) $today['month'];
$day = (string) $today['mday'];
$db_path = " /tmp/";
$db_path .= $year;
$db_path .= $month;
$db_path .= $day;
$db_path .= ".db";
$rocoto_path = "/work/apps/gnu_4.8.5/rocoto/1.2.1/bin/rocotorun";
//concatenate command
$exec_command = $rocoto_path;
$exec_command .= " -w ";
$exec_command .= $XML_file;
$exec_command .= " -d";
$exec_command .= $db_path;
shell_exec($exec_command);
echo ("SUCCess"); ?>
Thanks!