繁体   English   中英

没有可用消息 - 400 Bad request error getting while Angular API

[英]No Message available - 400 Bad request error getting while Angular API

当我调用后端 API 时收到消息不可用 400 错误请求。我通过 POSTMAN 工具测试了后端 API。 我从 POSTMAN 得到正确的 output。后端正常工作。 但是当我在 angular 端集成 API 时,出现如下错误,

在此处输入图像描述

我的 component.ts 文件中的订阅代码如下所示,

  this.modifypercentageService.checkUpdateRoomStatusApiMethod(element.nRoomAllocationId)
          .subscribe(data=> {console.log(data)}); 

我的服务层有以下代码,

  checkUpdateRoomStatusApiMethod(nRoomAllocationId:any) 
{
    return this.http
        .put(    
            this.baseurlService.getUrl()
            +this.portNumberService.getJointUseModifyPercentagePortNumber()
            +this.instituteidentifierService.getInstitute()
            +'/jointuse/modifypercentage/checkUpdateRoomStatus?nRoomAllocationId='+nRoomAllocationId,
            {
                headers: this.applicationconfigService.getHeader()
                
            }
        );
}

Output 当我交叉检查 POSTMAN 进行后端测试时,

在此处输入图像描述

我发现我从后端 API 得到 output,问题是 api 从 angular UI 端调用。

故障排除尝试,

通过交叉源交叉检查并通过 POSTMAN 工具测试后端。 两种情况都是正确的。 仅在 angular 端集成时出现问题,

任何人都可以建议有关我在 API 集成时在这里犯的任何错误的参考指南或信息吗?

Angular HttpClient PUT 有三个参数

放(网址:字符串,正文:任何| null,选项)

您正在传递标头而不是正文。 正确的放置请求将是

checkUpdateRoomStatusApiMethod(nRoomAllocationId: any) {
        return this.http
            .put(
                this.baseurlService.getUrl()
                + this.portNumberService.getJointUseModifyPercentagePortNumber()
                + this.instituteidentifierService.getInstitute()
                + '/jointuse/modifypercentage/checkUpdateRoomStatus', null,
                {
                    params: { nRoomAllocationId },
                    headers: this.applicationconfigService.getHeader()

                }
            );
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM