Uncaught (in promise): Response with status: 406 Not Acceptable for URL:


#1

In postman web url is working
LOGIN.HTML

<ion-content padding id="welcome1">
  
 <div class="imgcontainer"><br>
  <h4> My VAT Expert - Login </h4>
  </div>
<br>
  <form>

    <div class="container">
    <input type="text" placeholder="Enter Username" name="username" required>
    <input type="password" placeholder="Enter Password" name="password" required><br><br>
    <button  ion-button round class="wrapper" type="submit"(click)="Authenticate()">Login</button>

    <div>
       <button ion-button  class="register-btn"  (click)="Home()"block clear>Continue as Guest</button>
       <button ion-button icon-only class="register-btn" block clear><ion-icon ios="ios-key" md="md-key"></ion-icon>Forget Password?</button>
       </div> 
     </div>

  </form>

</ion-content>

LOGIN.TS FILE
import { Component } from ‘@angular/core’;
import { NavController, NavParams } from ‘ionic-angular’;
//import { Observable } from ‘rxjs/Observable’;
import { FormBuilder, FormGroup, Validators} from ‘@angular/forms’;

import { ApiProvider } from ‘./…/…/providers/api/api’;
import { MaintabsPage } from ‘…/maintabs/maintabs’;

//import { User } from ‘…/…/app/user’;

/**

@Component({
selector: ‘page-login’,
templateUrl: ‘login.html’,
})
export class LoginPage {

loginForm: FormGroup;
ResponseData: any;

constructor(public navCtrl: NavController, public builder: FormBuilder, public navParams: NavParams, public apiProvider: ApiProvider) {
console.log(“Constructor”);
this.loginForm = builder.group({
‘email’: [
’’, // default value
Validators.compose([Validators.required, Validators.pattern(’^[a-z0-9]+(.[_a-z0-9]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,15})$’)])
],
‘password’: [
’’,
Validators.compose([Validators.required, Validators.minLength(8)])
]
});
}

Authenticate(form) {
  //this.loginForm = form;
 //var email = this.loginForm.controls['username'].value;
  //var password = this.loginForm.controls['password'].value;

  //console.log("Email:"+email);

  let data = JSON.stringify(form);

  //var data = JSON.stringify({email: email, password: password});
  console.log("Data:"+data);

  this.ResponseData = this.apiProvider.HttpPost('userAuth', data, 'application/json');

  console.log("Response Data:"+JSON.stringify(this.ResponseData));

  //JSon Data

}

Home(){
this.navCtrl.setRoot(MaintabsPage);
}
}
```
Provider.ts

import { StatusBar } from '@ionic-native/status-bar';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

import { GlobalVars } from '../globalvars';

/*
  Generated class for the ApiProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/

@Injectable()
export class ApiProvider {

  constructor(public http: Http, public statusBar: StatusBar, public globalVars: GlobalVars) {
    console.log('Hello ApiProvider Provider');
        this.statusBar.styleDefault();
  }

   HttpPost(exturl, data, datatype):Promise<any> {
        //Start Status Bar
        this.statusBar.show();
        let url = this.globalVars.getBaseUrl() + exturl;
        console.log("URL:"+url + ", Data Type:"+datatype + ", Data:"+data);
        let headers = new Headers({ 'Content-Type': datatype });
        let options = new RequestOptions({ headers: headers });
        //Stop the status bar
        this.statusBar.hide();

      return this.http.post(url,data,options).toPromise()
      .then(this.extractData)
      .catch(this.handleErrorPromise);
  }   

  private extractData(res: Response) {

      return JSON.stringify(res.json()) || {};
      /*
      let body = res.json();
      console.log("Extracted Data:"+JSON.stringify(res.json()));
        return body.data || {};*/
    }

  public handleError(error) {
    console.log("ApiProvider - handleError: " + error);
    return error.json().message || 'Server error, please try again later';
  }

  private handleErrorPromise (error: Response | any) {
        console.error("ApiProvider - handleErrorPromise:" + error.message || error);
        return Promise.reject(error.message || error);
    } 

}

type or paste code here