Google Chrome Angular -注意:请求尚未完成

epggiuax  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(107)

在我的angular应用程序中,我调用get端点:https://example.test.de/example-1/rest-api/persons
此端点返回一些简单数据。在postman中,我可以毫无问题地调用端点,并得到快速响应。当我在Firefox中打开Angular UI时,端点也会返回快速结果。
当我在Google Chrome中打开应用程序时,端点从未返回任何值,并且在网络选项卡中我可以看到:注意:请求尚未完成!
我想这可能是一个缓存问题,所以我打开了一个谷歌Chrome Inkognito标签,但它也不工作。然而,它变得更加奇怪:有时它甚至在Google Chrome中工作,但有时不是。看起来超级随机。
在Angular Service中,我是这样做的:

public getPersons(): Observable<Person[]> {
    const headers = {
      headers: new HttpHeaders().set('Authorization', 'Bearer ' + this.keycloakService.getKeycloakInstance().token)
        .set('Content-Type', 'applciation/json')
    };
    let url = this.getApplicationBaseUrl();
    url =
      url +
      '/example-1/rest-api/persons';
    return this.httpService.get<Person[]>(url, headers);
}

Java SpringBoot后端:

@GetMapping(value = "/persons", produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ResponseEntity<List<Person>> getPersons(@Context final HttpServletRequest httpServletRequest,
      @RequestHeader("Authorization") final String authorization) throws Exception {
    return ResponseEntity.ok().body(this.service.getPersons());
  }

更新:Rest Endpoint现在返回一个带有Person类的列表,而不是String,但这没有帮助。

jdg4fx2g

jdg4fx2g1#

请发布您的'httpService'源代码。我还注意到你的'Content-Type'头值中有一个错字:

.set('Content-Type', 'applciation/json')

应为:

.set('Content-Type', 'application/json')

在此期间,您可以尝试以下操作:

public getPersons(): Observable<string[]> {
    const headers = new Headers({
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${auth_token}`
    });
    return this.http.get(apiUrl, { headers: headers });
}

相关问题