That header needs to be set by the server you're attempting to get the
resource from. It's not something you set in the request. Basically, your
browser does sends HTTP OPTIONS request to the server is expects it to
return this header. This is what it means when it says "preflight request".

Most likely, you will need to proxy the request through your own server to
overcome this limitation or find an already existing proxy.

On Sun, Jul 31, 2016, 10:03 Christian Leroy <[email protected]> wrote:

> Hello,
> I'm trying to retrieve tweets from twitter. So I'm using "
> https://auth0.com"; to manage the authentification part. But when I want
> to get tweets I got this following error:
>
>
> Response to preflight request doesn't pass access control check: No '
> Access-Control-Allow-Origin' header is present on the requested resource.
>
>
> So I have to set 'Access-Control-Allow-Origin' header but I can't find a
> way to do that with Angular-JWT, here my code
>
> import {Component, OnInit} from '@angular/core';
> import {AuthService} from './auth.service';
> import {AuthHttp, AuthConfig} from 'angular2-jwt';
> import { Headers } from '@angular/http';
> import 'rxjs/add/operator/map';
>
>
> @Component({
>     selector: 'ping',
>     template: '<h3>herlloo</h3>'
> })
> export class Ping {
>     message: string;
>
>     constructor(private auth: AuthService, private authHttp: AuthHttp) {}
>     public securedPing() {
>         
> this.authHttp.get(`https://api.twitter.com/1.1/search/tweets.json?q=from%3ACmdr_Hadfield%20%23nasa&result_type=popular`
>  
> <https://api.twitter.com/1.1/search/tweets.json?q=from%3ACmdr_Hadfield%20%23nasa&result_type=popular>)
>             .map(res => res.json())
>             .subscribe(
>                 data =>  {console.log("data:"+JSON.stringify(data)); return 
> this.message= data.text;},
>                 error => this.message = error._body || error
>             );
>     }
>
>     ngOnInit() {
>         this.securedPing();
>     }
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to