当我尝试发送" access_token"时遇到问题Lagom HTTP RestCall标题中的参数:
@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,因为&#34; access_token&#34;标题中没有。
但是,当我改变&#34; access_token&#34;通过&#34; access-token&#34;它有效。
当我做一些研究时,我知道我需要将CrosFilter播放到我的application.conf:
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
}
但即便如此,&#34; access_token&#34;标题参数始终不存在。
有任何帮助吗?请!
答案 0 :(得分:1)
这是因为你在名字中使用了下划线;除非you explicitly define them in its config file.
,否则它不会被禁止但不常见,而某些服务器(例如Nginx
会丢弃它们)
您也可以查看此问题:Why underscores are forbidden in HTTP header names。