Java 从请求头Spring Boot读取POJO
我试图解析请求头中从客户端发送到spring引导服务器端的对象Java 从请求头Spring Boot读取POJO,java,spring,spring-boot,Java,Spring,Spring Boot,我试图解析请求头中从客户端发送到spring引导服务器端的对象 @CrossOrigin(origins = "http://localhost") @RequestMapping(method = RequestMethod.GET, value = "/verify") public ResponseEntity<genericResponse> verifyToken(@RequestHeader("Authorization") Authorization header)
@CrossOrigin(origins = "http://localhost")
@RequestMapping(method = RequestMethod.GET, value = "/verify")
public ResponseEntity<genericResponse> verifyToken(@RequestHeader("Authorization") Authorization header) {
System.out.println(header.getAccess() + " - " + header.getTimeStamp() + " - ");
}
编辑
public class AuthorizationEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
System.out.println(text);
JSONObject obj = new JSONObject(text);
Authorization authorization = new Authorization();
authorization.setAccess(obj.getString("token"));
authorization.setTimeStamp(obj.getString("timeStamp"));
authorization.setAccess(obj.getString("access"));
setValue(authorization);
}
}
prinln
给了我文本[Object],然后给出了一个错误
JSONObject文本必须在1[字符2第1行]处以“{”开头
我的客户端请求是通过ajax实现的
function Auth() {
if (token != null && profile != null) {
var HEADER = {
token: token,
timeStamp: new Date().getTime(),
access: profile
}
console.log(JSON.stringify(HEADER));
/**
* This request would first request a token from the Auth0 Server
* The token is returned and that token is used to access API resource
*/
network.call(constants.VERIFY_URL, constants.TYPE_GET, {}, JSON.stringify(HEADER).trim());
// window.location.href = "dashboard.html";
} else {
webAuth.authorize();
}
}
发送的授权头的格式是什么?您有样本吗?我相信它是字符串而不是字符串object@pvpkiran我已经更新了问题检查问题的最后一部分我认为您应该验证这是否是发送授权标头的正确方式。第四个参数是否真的作为标头中的字符串发送etwork.call,还有别的吗?
function Auth() {
if (token != null && profile != null) {
var HEADER = {
token: token,
timeStamp: new Date().getTime(),
access: profile
}
console.log(JSON.stringify(HEADER));
/**
* This request would first request a token from the Auth0 Server
* The token is returned and that token is used to access API resource
*/
network.call(constants.VERIFY_URL, constants.TYPE_GET, {}, JSON.stringify(HEADER).trim());
// window.location.href = "dashboard.html";
} else {
webAuth.authorize();
}
}