Eradicating 401 “Unauthorised” responses followed by 200 “Ok” responses

前端 未结 5 2220
小鲜肉
小鲜肉 2020-12-29 05:19

I’ve got a situation with a large internal corporate web based application running ASP.NET 3.5 on IIS6 generating 401 “Unauthorised” responses followed by 200 “Ok” responses

5条回答
  •  庸人自扰
    2020-12-29 06:05

    TL;DR I put HTTP header information in HTTP body

    My example is in Angular, but any TypeScript/JavaScript (framework) might have the same issue.

    When doing a HTTP post call to my backend API, which requires headers with the logged in user information, I added my HTTP headers where my HTTP body should be and the headers were empty.

    PROBLEM

      markInstructionAsCompleted(visitScheduleId: string, instructionId: number) {
        return this.http.post(`${environment.apiUrl}/VisitInstructions/schedule/${visitScheduleId}/done/${instructionId}`, this.getHeaderWithAuthorization());
      }
    

    SOLUTION, notice that there's an added second argument to the HTTP post call, which is null

      markInstructionAsCompleted(visitScheduleId: string, instructionId: number) {
        return this.http.post(`${environment.apiUrl}/VisitInstructions/schedule/${visitScheduleId}/done/${instructionId}`, null, this.getHeaderWithAuthorization());
      }
    

提交回复
热议问题