How to create Http.get request in angular2 ionic2?

Hi I have the following details … How to make Api request in angular2



Method GET

Here’s an example, I’ll let you modify it for your needs. You can’t send a body of data with a GET request in Angular 2, you will have to use POST.

	    let headers = new Headers();
	    headers.append('Content-Type', 'application/json');

	    let data = {
	    	username: this.username,
	    	password: this.password
	    };'http://yoururl', JSON.stringify(data), {headers: headers})
	      .subscribe(res => {
	      }, (err) => {

Thank u … for the reply … @joshmorony


I have tried with your given method but, i have not got the result, I have tried Like :-

	let NamePass : {
		'username' : 'xyz',
		'password' : 'xyz'

where, username and password is the field name, JSON.stringify(NamePass), {headers: headers}).subscribe(data =>	console.log('Fetched :- ',data), err => console.log('Error :- ',err));


Please tell me what error you are getting , or Post Log?

  Error :-  Object { _body: error, status: 0, ok: false, statusText: "", headers: Object, type: 3, url: null }

I am not getting the data from that URL
(like :-!!!/!!!/xyz.php?XTYPE=2&YTYPE=1&page=0 ) (protected with ID & Password)

I am getting the the result correctly, when the URL is not protected with username & password.

Can you share the working code with us, if it is possible ?


I also stuggled for the same issue and now i fixed it please try this code,this vl work for sure

 isAuthenticated: boolean = false;

        var headers = new Headers();
        var creds = {username:"someemail@com",password:"sdasdasd"};
        headers.append('Content-Type', 'application/json');
        return new Promise((resolve) => {
  ``, creds, { headers: headers }).subscribe((data) => {
                    this.isAuthenticated = true;
            (error) => { 
                this.result = {status:this.isAuthenticated,error:error.json().error};


based on is authenticated u can navigate to different page

Try this,

import ‘rxjs/add/operator/map’;
import {Http, Headers,Response, RequestOptions} from “@angular/http”;

let postParams = {
password: “password”
var headers = new Headers();
headers.append(“Accept”, ‘application/json’);
let options = new RequestOptions({ headers: headers });'',postParams,options)
.map((res:Response) => res.json());


Hy All … i m suffering a huge problem …please someone help me @joshmorony

My url is
it redirect to login page :

my user password is : dilroop,Dilroop@123

it gives this error " Response for preflight is invalid (redirect)"

Please help me… i want to fetch data fro api…

That sounds like a CORS problem to me. You also want to make sure you have a proper SSL certificate and are using https endpoints, not http. That’s important for security in general, but especially so if you’re targeting iOS, because you may find your requests not working at all in deployment.

hy @rapropos thanks for replying…i tried using https endpoints …but still its not working…
here is the code

please help me…i have spent many days and my deadline is soon…
please help me in getting api data …