我无法从HTTPResponse typeScript获得一些标头

时间:2019-06-06 10:29:57

标签: spring typescript post postman httpresponse

在数据库中发布后,Spring-Java返回responseEntity。使用“邮递员”测试返回值将显示9个标头,其中包括所创建对象的ID。但是,当我使用用于图形界面的typeScript发布时,只得到3个标题。

Spring-Java代码:

@PostMapping
    @Transactional
    public ResponseEntity<Void> create(@Valid @RequestBody SpotCreateRequest spotCreateRequest) {
        Spot spot = new Spot();
        if (spotCreateRequest.getParentReference() != null) {
            Spot parentSpot = spotRepository.findById(spotCreateRequest.getParentReference()).orElseThrow(
                    () -> new EntityNotFoundException(String.format("Can't find parent spot with id = %s", spotCreateRequest.getParentReference())));

            spot.setParent(parentSpot);
            if (spotCreateRequest.getLevel() != null) {
                spot.setLevel(spotCreateRequest.getLevel());
            } else {
                spot.setLevel(parentSpot.getLevel() + 1);
            }
        } else {
            spot.setLevel(0);
        }

        spot.setLabel(spotCreateRequest.getLabel());
        spot.setCode(spotCreateRequest.getCode());
        spot = spotRepository.save(spot);
        final URI uri = fromController(getClass()).path("/{id}").buildAndExpand(spot.getId()).toUri();
        return ResponseEntity.created(uri).build();
    }

TypeScript代码:

this.spotService.create(createRequest).subscribe(success => {
          nbreChildren[0]--;
          this.createChildren(createRequest, nbreChildren);
          console.log(success.clone());
          /* this.createChildren(createRequest, nbreChildren.slice(1)); */
        });

我期望: the headers I get on postman

Location →http://localhost:9081/spots/df7a723d-372b-4309-bc1b-833ccaec499f
X-Content-Type-Options →nosniff
X-XSS-Protection →1; mode=block
Cache-Control →no-cache, no-store, max-age=0, must-revalidate
Pragma →no-cache
Expires →0
X-Frame-Options →DENY
Content-Length →0
Date →Thu, 06 Jun 2019 08:49:29 GMT

我得到: original image of the httpResponse below

HttpResponse {headers: HttpHeaders, status: 201, statusText: "OK", url: "http://localhost:9080/addressing-service/spots", ok: true, …}
body: null
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
ok: true
status: 201
statusText: "OK"
type: 4
url: "http://localhost:9080/addressing-service/spots"
__proto__: HttpResponseBase

0 个答案:

没有答案