Web API代码:
[HttpPost]
[ODataRoute("UploadDartDetails")]
public async Task<IHttpActionResult> UploadDartDetails([FromBody]CMM_DartBDO dartDetails)
{
}
尝试从Angular端发送对象CMM_DartBDO。我使用的是HttpClient模块。
public postDARTData() {
this.dartDetails.dartId=1;
this.dartDetails.documentVersionId=1;
this.dartDetails.contactId=1;
this.postDartdetails(this.dartDetails).subscribe((SucessMessage)=> console.log('res'+SucessMessage));
}
postDartdetails(model: any)
{
return this.http.post('http://localhost:1148/CMMService-service/UploadDartDetails', model).map(res=>res.json());
}
当它运行时,服务获得命中并在其结束时返回正确的响应,但角度代码获得错误406(未授权)。 请帮忙。
答案 0 :(得分:0)
您需要发送JSON对象,使用JSON.stringify
this.postDartdetails(JSON.stringify(this.dartDetails))
答案 1 :(得分:0)
试试这个:
public postDARTData() {
this.dartDetails.dartId=1;
this.dartDetails.documentVersionId=1;
this.dartDetails.contactId=1;
this.postDartdetails(this.dartDetails).subscribe(
(res) => {
console.log(res);
}, (err: HttpErrorResponse) => {
console.log(err.error);
console.log(err.name);
console.log(err.message);
console.log(err.status);
}
);
}
postDartdetails(model: any) {
return this.http.post('http://localhost:1148/CMMService-service/UploadDartDetails', model)
}