Header in http.get() in ionic 3


#1

hello
i want to put header in get request in http
how i can do this in ionic 3


#2

By reading the Angular documentation over here:

https://angular.io/docs/ts/latest/guide/server-communication.html

quick excerpt:

import { Headers, RequestOptions } from '@angular/http';


  create(name: string): Observable<Hero> {
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    return this.http.post(this.heroesUrl, { name }, options)
                    .map(this.extractData)
                    .catch(this.handleError);
  }

#3

thanks you
but
{ name }
stand for what


#4

It’s a post, so name is the payload. But if you wouldn’t be that lazy and opened up the docs, you would have probably seen that :wink: If you do a get request, a payload isn’t necessary. Just pass in the options.