angular - 无法从角度 7 将字符串值传递给 asp.net webapi
问题描述
我试图通过传递一个字符串值并得到 404 not found 错误从我的 angular 7 应用程序调用我的 asp.net web api 端点。如果您在下面看到我正在调用 getDocumentUploadDetailsByIds 并将字符串传递给它。我正在将整数数组转换为字符串并发送它
这是网址的外观: 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);
}
解决方案
尝试这个:
[HttpGet, Route("DetailsByIds")]
public IHttpActionResult DetailsByIds(string documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
按以下方式构建您的呼叫:
http://localhost:56888/api/documentupload/detailsByIds?documentIds=591006,591007
推荐阅读
- php - 在共享服务器上使用 Laravel 使用 Cron 会出现此错误,为什么?
- java - 通过单个套接字连接发送多个文件时java中的EOF异常
- excel - 删除庞大数据集中的空行
- android - android.view.InflateException:Binary XML file line #223: Binary XML file line #223: Error inflating class
- photon - 托管 Box2D MMO:Photon vs Lidgren vs GameSparks vs PlayFab
- python - 熊猫使用float64的最大小数位数
- python - 在数据框中的一列中显示 extractall 函数的结果
- javascript - 为什么我不能将返回的函数分配给类成员,但可以将其分配给变量
- javascript - 选择“否”时,YesNo 框不会终止代码
- python - Python - 带有多个闹钟的闹钟