Forum Topic - FRCAPI Response for preflight has invalid HTTP status code 405 (#production_server #JavaScript #novice): (2 Items)
   
FRCAPI Response for preflight has invalid HTTP status code 405 (#production_server #JavaScript #novice)  
No problems with the mock server, however the production server is giving me the following message:

"XMLHttpRequest cannot load https://frc-api.firstinspires.org/v2.0/2016/matches/WEEK0. Response for preflight has 
invalid HTTP status code 405."

Notes: 
I'm using the Chrome extension "Allow-Control-Allow-Origin" to enable CORS
I receive the same message regardless of whether file is open in my browser or hosted on AWS.
Error is the same with or without the commented headers below.

Code: (JavaScript)
    function sendRequest(){
      var username = document.getElementById('Username').value;
      var authorizationKey = document.getElementById('AuthorizationKey').value;
      var key = btoa(username + ":" + authorizationKey);
      var request = new XMLHttpRequest();
      var url = "https://frc-api.firstinspires.org/v2.0/2016/matches/WEEK0";
      request.open('GET', url);
      request.setRequestHeader('Accept', 'application/json');
      request.setRequestHeader('Authorization', 'Basic ' + key);
      // request.setRequestHeader('Access-Control-Allow-Origin', '*');
      // request.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type');
      // request.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
      request.onreadystatechange = function () {
        if (this.readyState === 4) {
          var myArr = JSON.parse(this.responseText);
          console.log('Status:', this.status);
          console.log('Headers:', this.getAllResponseHeaders());
          console.log('Body:', this.responseText);
        }
      }
      request.send();

Question:
What am I doing wrong?
Re: FRCAPI Response for preflight has invalid HTTP status code 405 (#production_server #JavaScript #novice)  
What I believe I was doing wrong was trying to access the API using JavaScript's xmlhttprequest, which sends an OPTIONS 
request to the API before sending the GET request. In the case of this API, the OPTIONS request returns 405 and 
therefore the GET request never sends. More knowledgeable members, please correct or expand upon my understanding for 
the benefit of the community. Has anyone had success with JavaScript?

P.S. I've had no problems with the API since switching to python for this project.