问题:尝试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):

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"); ?>

谢谢!

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐