1

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!

pehr.ans
  • 109
  • 1
  • 14
  • Not implemented means that the library/framework does not support that what you are trying to do. What PHP version are you running? What httpd server, version? – Gala Aug 08 '16 at 16:20
  • Some hosting company blocks the POST method. – frz3993 Aug 08 '16 at 16:24
  • It could be related to this: [http://stackoverflow.com/questions/3121451/why-do-i-get-this-501-not-implemented-error](http://stackoverflow.com/questions/3121451/why-do-i-get-this-501-not-implemented-error). I noticed that you check the host in the PHP so maybe you are posting this remotely? – Henders Aug 08 '16 at 16:26
  • to check @frz3993 point, set up a local WAMP/LAMP server, wich won't have such limitation. – technico Aug 08 '16 at 16:43
  • I just updated my post and included the server and php version – pehr.ans Aug 08 '16 at 16:48
  • I am having the same issue. Could you find a fix or an explantation ? – user2377141 Feb 14 '21 at 17:52

0 Answers0