我在这个问题上挣扎了很长时间。
我有一个客户端应用程序集,其中包含Angular6和使用ASP Core2.1创建的WebAPI。
为了我的职位要求,我做了这样的事情。
const params = {
TestData: newActions,
ExportAndExecute: true
};
this.httpClient.post('/tests/export', params, {headers: {}}).subscribe((result) => {
console.log(result);
});
其中httpclient.post方法为:
post(route: string, params: any, headers: object) {
return new Observable<any>(subscriber => {
this.httpClient.post<any>(this.baseUrl + route, params, headers).subscribe((result) => {
subscriber.next(result);
}, (error: Response) => {
this.handleRequestError(error);
});
});
}
我的API控制器操作如下:
[HttpPost]
[Route("/api/[controller]/export")]
[Authorize(AuthenticationSchemes = "JwtBearer")]
public async Task<HttpStatusCode> ExportTest( [FromBody] ExportTestModel model)
{
var result = HttpStatusCode.MisdirectedRequest;
}
模型类是:
public class ExportTestModel
{
public List<BsonDocument> TestData { get; set; }
public bool ExportAndExecute { get; set; }
}
我不知道为什么每次从客户机发送数据时,控制器操作中都是空的。我试着把它作为一个字符串对象发送,在控制器中接收
object
或
JObject
但一切都不如预期。
如果我收到数据
工作项目
我看得很清楚,但我不想这样做。
我觉得自己很蠢,但也许有人能指点我的做法有什么不对。