从服务器发送到c#api失败
我将发送到c#api。其中一个函数未发送到api。 你能告诉我原因吗。(使用此api的其他函数运行良好) 组成部分从服务器发送到c#api失败,c#,angular,api,C#,Angular,Api,我将发送到c#api。其中一个函数未发送到api。 你能告诉我原因吗。(使用此api的其他函数运行良好) 组成部分 this.loggedUser.aValidateUser(this.newlyRegistered.uMobile).subscribe(res => { alert("personal details were saved successfully"), this.active = 2; }, err => {
this.loggedUser.aValidateUser(this.newlyRegistered.uMobile).subscribe(res => {
alert("personal details were saved successfully"),
this.active = 2;
}, err => {
alert("There were wrong details. Please make the necessary changes");
}
);
}
角度服务:
aValidateUser(phoneNumber:string) {
return this.HTTP.post('http://localhost:54058/user/ValidateUser', phoneNumber ,this.httpOptions);
}
c#api:
c#api:
[HttpPost]
[路由(“上传文件”)]
public void UploadFile()//将passport保存在本地文件夹中
{
for(int i=0;i0)
{
var fileName=DateTime.Now.ToString(“yyyyMMdd_hhmmss”)+
GetFileName(file.FileName);
变量路径=
Path.Combine(HttpContext.Current.Server.MapPath(“~/UploadedFiles”),
文件名);
file.SaveAs(路径);
}
}
}
我希望有两件事能对你有所帮助
public bool ValidateUser(string phoneNumber)
到
return this.HTTP.post('http://localhost:54058/user/ValidateUser', phoneNumber ,this.httpOptions);
到
public class UserPhone {
public string Phone {get; set;}
}
控制器方法应更改如下:
public bool ValidateUser([FromBody] UserPhone phoneNumber)
和角度法,以:
return this.HTTP.post('http://localhost:54058/user/ValidateUser', {phone: phoneNumber} ,this.httpOptions);
您的代理设置是否从angular到.net?角度在4200上运行default@d.moncada这是对c#api的调用。如果其他函数工作正常,也许您应该看看它们,看看它们有什么不同?一定有。您还可以添加此类工作函数的示例。“不发送”是什么意思?在浏览器中,您是否看到请求发出但未到达服务器?@GrayCat请参阅编辑。发送到服务器时出现404错误。
return this.HTTP.post('http://localhost:54058/user/ValidateUser', phoneNumber ,this.httpOptions);
return this.HTTP.post('http://localhost:54058/user/ValidateUser', JSON.stringify(phoneNumber) ,this.httpOptions);
public class UserPhone {
public string Phone {get; set;}
}
public bool ValidateUser([FromBody] UserPhone phoneNumber)
return this.HTTP.post('http://localhost:54058/user/ValidateUser', {phone: phoneNumber} ,this.httpOptions);