问题:尝试POST
请求时收到501未实现的错误。 GET
方法工作得很好,但是它的数据长度限制使得我希望传递给 PHP 脚本的XML
字符串不可行。
背景:我根据一些使用JavaScript的用户输入生成XML字符串。接下来,我尝试将此XML
字符串(在编码之后)传递给 PHP 脚本,以将字符串写为服务器上的XML
文件并执行关于它的命令。
服务器: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"); ?>
谢谢!