如何将Kotlin中的位置地址添加到ResponseEntity中的标头构建器

接收到302状态时,我需要设置位置网址以进行重定向。我搜索了很多页面,但没有找到实现的结果。那么如何设置地址以及该代码中的位置呢?

我以某种方式尝试过,但不确定是否可以。

override fun getDocumentContent(
        @PathVariable repository: String,@PathVariable dmsId: String,@RequestParam version: String?
    ): ResponseEntity<Resource> {

        val content: DocumentContent = documentService.getDocumentContent(repository,dmsId,version)
        val encodedFilename = URLEncoder.encode(content.filename,"UTF-8").replace("+"," ")
        return try {
            ResponseEntity
                .ok()
                .contentType(MediaType.parseMediaType(content.contentType!!))
                .header(
                    HttpHeaders.CONTENT_DISPOSITION,// sets filename twice for interoperability of multiple browsers
                    """attachment; filename="$encodedFilename"; filename*="UTF-8''$encodedFilename""""
                )
                .header(HttpHeaders.accESS_CONTROL_EXPOSE_HEADERS,HttpHeaders.CONTENT_DISPOSITION)
                .body(ByteArrayResource(content.data!!))
        } catch (e: GeneralErrorException) {
            val location = toString("documents/err/$dmsId?errMsg=Klient / ESSO nenalezen/a.")
            ResponseEntity
                .status(HttpStatus.FOUND)
                .header(HttpHeaders.LOCATION,webApiLinkBuilder
                    .build(methodOn(DocumentsController::class.java)
                        .getDocumentContent(repository,version),Backends.DOC))
                .header(HttpHeaders.accESS_CONTROL_EXPOSE_HEADERS,HttpHeaders.LOCATION,location)
                .build()
        }
    }
wxslzx 回答:如何将Kotlin中的位置地址添加到ResponseEntity中的标头构建器

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3133382.html

大家都在问