Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59808

REST simpleserver ignores the moodlewsrestformat parameter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.2.6, 3.3.3
    • 3.2.5, 3.3.2, 3.4
    • Web Services
    • MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
    • MOODLE_32_STABLE, MOODLE_33_STABLE
    • wip-MDL-59808-master
    • Hide
      1. Enable web services and REST in "Manage protocols"
      2. Enable web services authentication plugin
      3. Enable the mobile web service (or create a new one with the function in it and make it available to selected user)
      4. Make sure a selected user has capability webservice/rest:use
      5. Execute

        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info"
        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=xml"
        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=json"
        

        Make sure the first two return data in XML and the last one in JSON

      Show
      Enable web services and REST in "Manage protocols" Enable web services authentication plugin Enable the mobile web service (or create a new one with the function in it and make it available to selected user) Make sure a selected user has capability webservice/rest:use Execute curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info" curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=xml" curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=json" Make sure the first two return data in XML and the last one in JSON

      Short description:
      webservice/rest/simpleserver.php reads moodlewsrestformat parameter and then unsets and ignores it. Therefore there is no way to set JSON encoding for REST protocol in simpleserver.php.

      Long description:

      At same point following code was added to both webservice/rest/simpleserver.php and webservice/rest/server.php:

      $restformat = optional_param('moodlewsrestformat', 'xml', PARAM_ALPHA);
       
      if (isset($_REQUEST['moodlewsrestformat'])) {
      unset($_REQUEST['moodlewsrestformat']);
      }
      if (isset($_GET['moodlewsrestformat'])) {
      unset($_GET['moodlewsrestformat']);
      }
      if (isset($_POST['moodlewsrestformat'])) {
      unset($_POST['moodlewsrestformat']);
      }
       
      $server = new webservice_rest_server(WEBSERVICE_AUTHMETHOD_XXX, $restformat);
      

      webservice/rest/server.php was later refactored - isset / unset lines were removed and $restformat from webservice_rest_server call - but simpleserver.php was not - the isset / unset lines are still there.
      And because webservice_rest_server class checks the data retrieved from GET/POST and moodlewsrestformat is not there anymore, it will always use XML as a format.

            marina Marina Glancy
            tmuras Tomasz Muras
            Juan Leyva Juan Leyva
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Damyon Wiese Damyon Wiese
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.