我试图通过传递字符串值并得到404 not found错误,从我的angular 7应用程序调用asp.net Web api端点。如果您在下面看到,我正在调用getDocumentUploadDetailsByIds并将字符串传递给它。我正在将整数数组转换为字符串并将其发送
URL的外观如下:http://localhost:56888/api/documentupload/detailsByIds/591006,591007
组件
public createDocument() {
const documents: IDocumentDetails[] = this.files.map(doc => {
return { // notice just a curly bracket, and in the same line with 'return'
file: doc.fileDropEntry.fileEntry,
documentTypeId: doc.selectedDocumentItem.Id,
name: doc.name,
documentDate: doc.selectedDate
};
});
this.documents = { managerStrategyId: 0, documentDetails: null };
this.documents.managerStrategyId = this.ManagerStrategyId;
this.documents.documentDetails = documents;
this.documentUploadService.createDocumentUpload(this.documents)
.then((result) => {
if (result) {
this.documentIds.ids = Object.keys(result).map(k => result[k]);
this.getDocumentUploadDetailsByIds(this.documentIds.ids.toString());
this.setGridOptions();
this.setColumns();
this.notify.success('Documents uploaded Successfully');
}
}).catch(err => {
this.notify.error('An Error Has Occured While uploading the documents');
});
}
public getDocumentUploadDetailsByIds(documentIds) {
if (this.ManagerStrategyId != null) {
this.Loading = true;
this.initGrid();
this.documentUploadService.getDocumentUploadDetailsByIds(documentIds)
.subscribe(data => {
this.DocumentUploadDetails = data;
this.Loading = false;
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
}
服务组件
getDocumentUploadDetailsByIds(documentIds: string) {
return this.mgr360CommonService.httpGet('/api/documentupload/detailsByIds/' + documentIds );
}
httpGet(url: string): Observable<any> {
return this.httpClient.get( this.webApiLocation + url, httpPostOptions)
.pipe(map((response: Response) => {
return response;
}), catchError(error => {
this.onError(error);
return Promise.reject(error);
}));
}
服务器端
[HttpGet]
[SkipTokenAuthorization]
public IHttpActionResult DetailsByIds(string documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
答案 0 :(得分:1)
尝试一下:
[HttpGet, Route("DetailsByIds")]
public IHttpActionResult DetailsByIds(string documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
通过以下方式构建您的通话:
http://localhost:56888/api/documentupload/detailsByIds?documentIds=591006,591007