为什么spring-data-rest中的alps(或profile)路径返回带有非匹配头的json主体Content-Type:text / html?

时间:2017-02-03 01:20:48

标签: spring-data-rest

现在我的spring-data-rest(spring-boot 1.4.3.RELEASE)提供的控制器的默认Content-Type是application/hal+json,这是有道理的。如果我使用chrome,我会为我的应用程序的根获取application/hal+json,因为chrome使用了"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"的Accept标头。但是,/profile(正式/alps)URL提供text / html,即使响应正文是json(使得Content-Type与正文不匹配)。如果你只要求application / json,那么你会得到正确的响应标题。

以下是错误工作的情况(当文档/正文返回时返回text / html不是text / html):

$ http --verbose "http://localhost:8080/v1/profile/eldEvents" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"

GET /v1/profile/eldEvents HTTP/1.1
Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.2



HTTP/1.1 200 
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Location, X-Auth, Authorization
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: text/html;charset=UTF-8
Date: Fri, 03 Feb 2017 01:16:14 GMT
Expires: 0
Pragma: no-cache
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Transfer-Encoding: chunked
X-Application-Context: application
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
  "alps" : {
    "version" : "1.0",
    "descriptors" : [ {
      "id" : "eldEvent-representation",
      "href" : "http://localhost:8080/v1/profile/eldEvents",
      "descriptors" : [ {
        "name" : "sequenceId",
        "type" : "SEMANTIC"
      }, {
...

删除剩下的响应,你可以从上面看到它是json数据。

我认为上述请求的正确Content-Type应该类似于“application / json”。

1 个答案:

答案 0 :(得分:1)

如果这仍然与您相关:我已通过针对未定义/profile/*的{​​{1}}手动覆盖所有请求来解决此问题。

content-type