Http post request don't work in ionic3 with node.js

#1

I want to create a simple registration form in ionic v3. But I’m getting this error;
POST http://localhost:8100/null 404 (Not Found)
ERROR Response {_body: “↵↵↵<meta char…dy>↵

Cannot POST /null
↵↵↵”, status: 404, ok: false, statusText: “Not Found”, headers: Headers, …}

My code here;

auth.service.ts

signup(user_model:any):Observable<any>{ 
    let url:"http://localhost:3000/user/signup";
    let body = JSON.stringify(user_model);
    let headers = new Headers({'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    console.log("body:",body);


    return this.http.post(url, body, options)
    .map((response: Response) => response.json());
  
}

signup.ts

signup(){
    let loader = this.loaderCtrl.create({
      content:"Please wait..."
    })
    loader.present();

   
    console.log(this.user_model);

    this.authService.signup(this.user_model).subscribe(); 
    this.navCtrl.push(TabsPage);
    loader.dismiss();
    
    

  }

i am using node.js for backend.I tested it with postman and it works fine. Please help me thanks a lot…

#2

Hey Hakan07.

There is a typo in your url definition.

let url:"http://localhost:3000/user/signup";

Must be:

let url: string = "http://localhost:3000/user/signup";

Mike

1 Like
#3

Oh… :sweat_smile: Thanks a lot Mike…