【发布时间】:2020-01-15 13:16:09
【问题描述】:
我已经使用 order/:orderId 定义了一条路线,并且我正在尝试对 orderId 进行哈希处理以避免显示真实的 orderId。我研究了散列的方式,并决定使用 32 位混合函数。我已经使用 PostMan 测试了该功能,一切正常,但是在访问所需的端点时,我收到 415 错误。实现如下所示:
this.orderService.createOrder(newOrder)
.pipe(
takeUntil(this.ngUnsubscribe)
).subscribe(result => {
console.log(result);
this.router.navigate(['order', result])
});
服务看起来像这样:
createOrder(order:OrderModel): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/*'
})
};
return this.http.post(this.BASE_URL+'Orders/', order, httpOptions)
.pipe(
catchError(this.handleError('createOrder'))
)
subscribe 中的结果应该是 orderId 的哈希版本。
【问题讨论】:
-
显然原因是
'Content-Type': 'application/*'...没有服务器端代码,我们无法猜测预期的类型...但我 90% 确定它应该是 json (application/json)跨度> -
通常我会查看正确的请求(由 Postman 发送)、不正确的请求(由 Web 应用程序发送)并进行比较。有什么区别?
-
@Selvin 谢谢,那是我的问题。错过了
标签: c# angular observable postman