如何从控制器获取响应?

时间:2018-02-15 11:14:31

标签: java angular rest typescript

在我的角度4应用程序中,我可以打电话给我的休息服务,但我无法打印我的回复。我错过了什么?以下是我的代码。

控制器:

@RequestMapping("/rest/auth")
    public Response authenticateUser() 
    {
        String token = issue("test");
         AnimalTok tok = new AnimalTok();
         tok.setTo(token);
         return Response.ok(tok).build();
    }

ts文件调用:

 getAnimalData():  Promise<string> {
    let context:String =  document.location.pathname.substring(0, document.location.pathname.indexOf("/",2)) + "/";
    return this.http.get(context  + 'rest/auth/')
      .toPromise()
      .then(response => response.text() as string)
      .catch(this.handleError);
  }

获得以下例外:

errors.ts:42 ERROR Error: Uncaught (in promise): Response with status: 404 OK for URL: http://localhost:89795/rest/auth/
    at resolvePromise (zone.js:809)
    at resolvePromise (zone.js:775)
    at zone.js:858
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (ng_zone.ts:288)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1517)

0 个答案:

没有答案