ionic2-rest-authentication
ionic2-rest-authentication copied to clipboard
Sending json values to service
I was not able to sending values to rest api. I don't know what I done wrong. help me get rid of this!
here is my code.
import { Injectable } from '@angular/core'; import { Http, Headers, RequestOptions } from '@angular/http'; import 'rxjs/add/operator/toPromise';
@Injectable() export class AuthServiceProvider {
http: any;
baseUrl: string;
constructor(http: Http) { //console.log('Hello AuthServiceProvider Provider'); this.http = http; this.baseUrl = 'http://www.60.207.162.74:8080/api/WebApi/Login';
} login(username, password) {
return new Promise((resolve, reject) => {
let body = JSON.stringify({ "LoginName": username, "Password": password });
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({
headers: headers
});
return this.http.post(this.baseUrl, body, options)
.subscribe(res => {
resolve(res.json());
alert("Success"); //if everything go well
},
(err) => {
reject(err);
});
});
}
}
yea..I got the solution!!. here main problem with url. It' working fine for Phonegap but not for Ionic, Im still wondering!