ionic2-rest-authentication icon indicating copy to clipboard operation
ionic2-rest-authentication copied to clipboard

Sending json values to service

Open ramukodandapuram opened this issue 9 years ago • 1 comments

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);
        
      });
  });

}

}

ramukodandapuram avatar Aug 02 '17 06:08 ramukodandapuram

yea..I got the solution!!. here main problem with url. It' working fine for Phonegap but not for Ionic, Im still wondering!

ramukodandapuram avatar Aug 03 '17 14:08 ramukodandapuram