还有其他有关此问题的答案,但没有一个解决。具体来说,我正在发送一个Accept
标头。
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.Collections;
import java.util.Map;
@Controller
@RequestMapping(value = "/x")
public class A {
@RequestMapping(value = "/y",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Map<String, Boolean> stepOneLogin(@RequestHeader(value = "abc") String abc,
@RequestHeader(value = "def") String def) {
return Collections.singletonMap("success", true);
}
}
我的请求如下:
curl -X GET \
http://localhost:8080/context/x/y \
-H 'Accept: application/json' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: fa6ad6c1-0b4c-400b-9d1c-982xx3e532b5' \
-H 'abc: abc' \
-H 'def: def'
响应为HTTP/1.1 406
:
根据请求中收到的主动协商标头字段,目标资源没有用户代理可以接受的当前表示形式,并且服务器不愿意提供默认表示形式。