title: Angular 5 HTTP get method not allowed when accessing WebApi
body: <p>I have this service:</p>
  
  <pre><code>import { HttpClient, HttpHeaders } from '@angular/common/http';
  import { Injectable } from '@angular/core';
  
  @Injectable()
  export class LoginService {
  
    constructor(private http: HttpClient) {}
  
    getUsers() {
      const options = {
          headers: new HttpHeaders({
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'GET',
            'Access-Control-Allow-Headers': 'Origin, Content-Type',
            'Content-Type': 'text/xml'
          })
        };
  
      return this.http.get('myurl', options);
    }
  }
  </code></pre>
  
  <p>And I'm trying to access an API which has only <code>GET</code>. This particular resource allows anonymous access.</p>
  
  <p>However, I get the following errors (in Chrome console):</p>
  
  <blockquote>
    <p>OPTIONS myurl 405 (Method Not Allowed)</p>
    
    <p>Failed to load myurl: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' is therefore not allowed access. The response had HTTP status code 405.</p>
  </blockquote>
  
  <p>Any ideas on how to fix these errors?</p>