gpt4 book ai didi

Angular 6 : HttpErrorResponse SyntaxError: Unexpected token s in JSON

转载 作者:太空狗 更新时间:2023-10-29 17:09:48 27 4
gpt4 key购买 nike

我正在发布一个请求,并且我想收到一个“成功”字符串作为响应。我收到一个 HttpResponseError,其中包含下图中发布的以下信息。

enter image description here

采购订单服务

postPurchaseOrderCustom(purchaseOrderCustom: PurchaseOrderSaveCustom) {
const url = `${this.localUrl}purchaseOrderCustom`;
return this.http.post<String>(url, purchaseOrderCustom, {headers: this.header})
.pipe(
catchError(this.handleError('postPurchaseOrderCustom', 'I am an error'))
);
}

采购订单组件

this.purchaseOrderService.postPurchaseOrderCustom(purchaseOrderCustom).subscribe( response => {
console.log("Testing", response);
},
error => {
console.error('errorMsg',error );
}

我这样做的方式与文档中的方式相同。请向我指出我做错了什么。

error shown when I implement answer provided by @Muhammed

最佳答案

这与你的 api 响应类型有关,success 不是有效的 json 格式,默认情况下 HttpClient 是预期的 json 响应类型,稍后尝试解析它。您可以通过将响应类型设置为 text like this

来解决此问题
return this.http.post<String>(
url,
purchaseOrderCustom,
{ headers: this.header, responseType: 'text' }
)
.pipe(
catchError(this.handleError('postPurchaseOrderCustom', 'I am an error')
));

关于 Angular 6 : HttpErrorResponse SyntaxError: Unexpected token s in JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51583757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com