简体   繁体   中英

Dynamic post call giving error 404 on angular 5

I am making a post call, where post parameter getting from another get call. If I pass the post parameter manually its working fine.

doPost(): Observable<any> {
    return this.http.post(this.URL+ '/GetEmp', {emp:[{"empId":8106, "name":"xxxxx"}]});    
}

But when I am calling it dynamically its showing 404 error

doPost(val): Observable<any> {
    this.postD = JSON.stringify(val);
    return this.http.post(this.URL+ '/GetEmp', {emp:this.postD});    
}

Here I am calling like this

this.configs.doPost(pval).subscribe(
    data => {this.post = data['org']},           
    err => console.error(err),
    () => console.log('done loading employee' + this.post)
);

Requirement is that I am making one GET request, through that I am getting the value and populated the drop-down, once I select the value from drop-down, this value needs to use for parameter in post call.

Here I am able to get the value from drop-down, but once I am passing it through post request its giving 404 error.

Please help on this.

hTTP post requires an object so please dont stringify it

doPost(val): Observable<any> {
    return this.http.post(this.URL+ '/GetEmp', { emp: val });    
}

Here is the syntax:

post(url: string, body: any, options?: RequestOptionsArgs) :

  • Observable url: This is HTTP URL using which we post data
    to the server.
  • body: This is the object which we need to post to the server.
  • options: This is optional. Here we pass the instance of
    RequestOptionsArgs that uses headers.
  • Observable: This is the return type of Http.post().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM