Method not allowed

hi guys i am new in ionic 2,
i am calling a api and facing an error 405 (Method Not Allowed)
don’t understand what is the problem

please see my code below and help me to solve this

in provider:

GetVisitor(AuthToken, MoblieNumber){
    let headers = new Headers({
      'AuthToken': AuthToken
    });

    let options = new RequestOptions({
      headers: headers
    });
    return new Promise(resolve => {
      this.http.get("http://122.160.53.175:83/SmartAccess/WebRequest/GetVisitor?MoblieNumber="+MoblieNumber, options)
        .map(res => res.json())
        .subscribe(
        data => { resolve(data) },
        err => { console.log(err) }
        );
    });
  }

in page.ts:

mobileNo: any;
searchVisitor(event, item) {
    console.log('mobile: ' + this.Mobile);
    this.storage.get('token').then((value) => {
      console.log('token: ' + JSON.parse(value).AuthToken);
      this.userProvider.GetVisitor(JSON.parse(value).AuthToken, this.Mobile.toString()).then(data => {
        console.log('data: ' + data)
        if (data) {
          this.navCtrl.push('VisitorAccessPage',{
            item:item
          });
        }
        if(!data){
          console.log('no data')
        }
      });
    });
  }

in html:

<form  #registerForm="ngForm">
    <ion-item>
      <ion-label color="primary" floating>Enter Visitor's Mobile Number</ion-label>
      <ion-input type="text" minlength="10" maxlength="10" pattern="^[0-9]{10,10}$" name="mobile" #mobile="ngModel" [(ngModel)]="Mobile"
        required>
      </ion-input>
    </ion-item>
                <div *ngIf="mobile.errors && (mobile.dirty || mobile.touched)" class="divAlert">
                  <div [hidden]=" !mobile.errors.required ">This field can't be empty</div>
                  <div [hidden]=" !mobile.errors.pattern ">Use 10digit Number Only</div>
                </div>
    <button ion-button class="submit-btn" full style="float:left" type="submit" [disabled]="!registerForm.form.valid" (click)="searchVisitor($event, item)">Search</button>

  </form>

Seems the server doesn’t want to reply to your GET request.
Are you sure the request is correct?

Use your browser’s dev tool’s network panel to see the actual request being sent.

yes GET rqst is corrent. i hv checked it in postman. postman giving the values correctly

yes GET rqst is corrent. i hv checked it in postman. postman giving the values correctly
rply from postman

and this is rply from browser

See:

1 Like

The error messages are pretty clear. OPTIONS request is done because mobile context, returns 405 instead of 200 it has to return. (This doesn’t happen in Postman, so you can’t just compare)