Lagom:"access_token" Header 参数没有值
Lagom: No value Present for "access_token" Header param
当我尝试在 Lagom HTTP RestCall 的 Header 中发送 "access_token" 参数时遇到问题:
@Override
public HeaderServiceCall<NotUsed, GetUserInfoWrapperResponse> getUserInfo() {
return (request, requestBody) -> {
UUID userId;
try {
userId = UUID.fromString(request.getHeader("access_token").get());
System.out.println("user id = " + userId);
return userEntityRef(userId).ask(new GetUserInfoCommand()).thenApply(reply -> Pair.create(ResponseHeader.OK, reply.userInfo.get()));
} catch (Exception e) {
throw new NotFound("User with access_token ");
}
};
}
我总是得到 NotFoundException,因为 "access_token" 不在 header.
中
但是,当我将 "access_token" 更改为 "access-token" 时,它起作用了。
当我做一些研究时,我明白我需要对我的 application.conf:
播放 CrosFilter
play.http.filters = "com.test.user.impl.AccessFilter"
play.filters.cors {
// review the values of all these settings to fulfill your needs. These values are not meant for production.
pathPrefixes = ["/cms"]
allowedOrigins = null
allowedHttpMethods = null
allowedHttpHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
# The exposed headers
exposedHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
supportsCredentials = false
preflightMaxAge = 6 hour
}
但即便如此,"access_token" header 参数始终不存在。
有什么帮助吗?请!
这是因为您在名称中使用了下划线;它不被禁止但并不常见,一些服务器如 Nginx
会删除它们,除非 you explicitly define them in its config file.
你也可以看看这个问题:。
当我尝试在 Lagom HTTP RestCall 的 Header 中发送 "access_token" 参数时遇到问题:
@Override
public HeaderServiceCall<NotUsed, GetUserInfoWrapperResponse> getUserInfo() {
return (request, requestBody) -> {
UUID userId;
try {
userId = UUID.fromString(request.getHeader("access_token").get());
System.out.println("user id = " + userId);
return userEntityRef(userId).ask(new GetUserInfoCommand()).thenApply(reply -> Pair.create(ResponseHeader.OK, reply.userInfo.get()));
} catch (Exception e) {
throw new NotFound("User with access_token ");
}
};
}
我总是得到 NotFoundException,因为 "access_token" 不在 header.
中但是,当我将 "access_token" 更改为 "access-token" 时,它起作用了。
当我做一些研究时,我明白我需要对我的 application.conf:
播放 CrosFilterplay.http.filters = "com.test.user.impl.AccessFilter"
play.filters.cors {
// review the values of all these settings to fulfill your needs. These values are not meant for production.
pathPrefixes = ["/cms"]
allowedOrigins = null
allowedHttpMethods = null
allowedHttpHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
# The exposed headers
exposedHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
supportsCredentials = false
preflightMaxAge = 6 hour
}
但即便如此,"access_token" header 参数始终不存在。
有什么帮助吗?请!
这是因为您在名称中使用了下划线;它不被禁止但并不常见,一些服务器如 Nginx
会删除它们,除非 you explicitly define them in its config file.
你也可以看看这个问题:。