简体   繁体   English

动态调用后在角度5上给出错误404

[英]Dynamic post call giving error 404 on angular 5

I am making a post call, where post parameter getting from another get call. 我正在进行post调用,其中post参数是从另一个get调用获取的。 If I pass the post parameter manually its working fine. 如果我手动传递post参数,它的工作正常。

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 但是当我动态调用它时,显示404错误

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. 要求是我发出一个GET请求,通过我获取值并填充下拉列表,一旦我从下拉列表中选择了值,该值就需要在调用后用作参数。

Here I am able to get the value from drop-down, but once I am passing it through post request its giving 404 error. 在这里,我可以从下拉列表中获取该值,但是一旦我将其传递给post请求,它就会给出404错误。

Please help on this. 请帮忙。

hTTP post requires an object so please dont stringify it hTTP post需要一个对象,请不要对其进行stringify

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 可观察的网址:这是我们用来发布数据的HTTP网址
    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. 使用标头的RequestOptionsArgs。
  • Observable: This is the return type of Http.post(). 可观察:这是Http.post()的返回类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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