Web API正在IIS中运行。我使用CLI来运行角度项目。 Http帖子两次点击Web API方法。 首次使用的Web API参数为null。第二次带参数。
API
[System.Web.Http.Route("api/Location/AddNewLocationSection")]
[HttpPost]
[AcceptVerbs("OPTIONS")]
public GenericResult AddNewCustomerLocationSection(GenericParam<CustomerLocationSectionTreeItem> locationSectionParam)
{
//due to double post i'm doing this check
if (locationSectionParam != null && locationSectionParam.Parameter != null)
{
//logic
}
}
角度服务
addNewLocationSection(locationSectionDetails: CustomerLocationSectionInfo): Observable<any> {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this._configuration.AddNewLocation JSON.stringify({ parameter: locationSectionDetails }), new RequestOptions({ headers: headers }))
.map(this.extractData)
.catch(this.handleError);
}
组件
this.locationDetailService.addNewLocationSection(this.locationSectionDetails)
.subscribe(success => this.reLoadCustomerLocationTree(success, "Add"),
error => this.errorMessage = <any>error);
我怎么能避免这个双重帖子。提前谢谢。
答案 0 :(得分:1)
如果你看第一个电话,那就是一个OPTIONS请求。这是浏览器发送的请求,用于检查端点的有效性。我认为你不能改变它!