title: Access to API Method from origin has been blocked by CORS policy
body: <p>I'm using .Net Core to build API and Angular Web application to consume those APIs. Both are hosted locally with different ports.</p>
  
  <p><strong>.Net Core API:</strong> <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a></p>
  
  <p><strong>Angular Web App:</strong> <a href="http://localhost:4444" rel="nofollow noreferrer">http://localhost:4444</a></p>
  
  <p>Here are my Service methods in Angular</p>
  
  <pre><code>export class AdvertisementService {
    // Define API 
    apiURL = environment.apiUrl;
  
    constructor(private http: HttpClient) {}
  
    // Configure HTTP Options
    httpOptions = {
      headers: new HttpHeaders({
        'Content-Type': 'application/json'
      })
    }
  
    // HttpClient API get() method =&gt; Fetch Advertisement List.
    getAdvertisements(): Observable&lt;Advertisement[]&gt; {
      return this.http.get&lt;Advertisement&gt;(this.apiURL + '/Advertisements')
                      .pipe(retry(1),catchError(this.handleError))
    }
  
    // HttpClient API post() method =&gt; Create Advertisement
    createAdvertisement(advertisement): Observable&lt;Advertisement&gt; {
      return this.http.post&lt;Advertisement&gt;(this.apiURL + '/Advertisements', JSON.stringify(advertisement), this.httpOptions)
      .pipe(retry(1),catchError(this.handleError))
    }  
  
    private handleError(error: any): Promise&lt;any&gt; {
      console.error('An error occurred', error); // for demo purposes only
      return Promise.reject(error.message || error);
    }
  }
  </code></pre>
  
  <p>When I call API methods via Angular App it is throwing following error:</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at
    '<a href="http://localhost:5000/api/Advertisements" rel="nofollow noreferrer">http://localhost:5000/api/Advertisements</a>' from origin
    '<a href="http://localhost:4444" rel="nofollow noreferrer">http://localhost:4444</a>' has been blocked by CORS policy: Request
    header field content-type is not allowed by
    Access-Control-Allow-Headers in preflight response.</p>
  </blockquote>
  
  <p>I added CORS in my .Net Core as below in <strong>ConfigureServices</strong> method:</p>
  
  <pre><code> services.AddCors(options =&gt;
   {
       options.AddPolicy(MyAllowSpecificOrigins,
       builder =&gt;
       {
           builder.WithOrigins("http://localhost:4444");
       });
   });
  </code></pre>