Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70433

Capacitor Angular 8 all requests fail with HttpHeaders

$
0
0

@tharrington1 wrote:

Every API request I try to make with HTTP headers fails with this error:

Failed to load resource: Origin capacitor://localhost is not allowed by Access-Control-Allow-Origin.

However the request works when sending an empty as the header. How can I get around this issue?
Here is the code:

const httpOptions = {
      headers: new HttpHeaders({
        'Access-Control-Allow-Origin' : '*',
        'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
        'Authorization' : 'Bearer ' + this.token,
        'Content-Type': 'application/json'
      })
    };

    return this.http.get(endpoint, httpOptions);

Here is my ionic info:

ionic info

Ionic:

   Ionic CLI                     : 6.9.2 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 2.0.1
   @capacitor/core : 2.0.1

Utility:

   cordova-res (update available: 0.14.0) : 0.13.0
   native-run (update available: 1.0.0)   : 0.3.0

System:

   NodeJS : v10.15.1 (/usr/local/bin/node)
   npm    : 6.14.5
   OS     : macOS Catalina

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70433

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>