在 java 中通过邮递员发送 headers
Get headers sent through postman in java
我正在使用 apache cxf 将我的 java 应用程序公开为 REST api。
如何在我的 java 应用程序 @GET 方法中获取 api 调用方发送的 header 详细信息
Apache CXF 实现了 JAX-RS 规范。所以你可以注入 HttpHeaders
in your resource class or resource methods using @Context
:
@Context
HttpHeaders httpHeaders;
然后你可以使用 HttpHeaders
API 得到 header 值:
HttpHeaders#getHeaderString(String)
HttpHeaders#getRequestHeaders()
HttpHeaders#getHeaderString(String)
如果您需要标准 HTTP header 的值,请考虑使用 constants available in the HttpHeaders
API:
// Get the value of the Authorization header
String authorizationHeader = httpHeaders.getHeaderString(HttpHeaders.AUTHORIZATION);
有关上下文类型的更多详细信息,请参阅 Apache CXF documentation。
我正在使用 apache cxf 将我的 java 应用程序公开为 REST api。
如何在我的 java 应用程序 @GET 方法中获取 api 调用方发送的 header 详细信息
Apache CXF 实现了 JAX-RS 规范。所以你可以注入 HttpHeaders
in your resource class or resource methods using @Context
:
@Context
HttpHeaders httpHeaders;
然后你可以使用 HttpHeaders
API 得到 header 值:
HttpHeaders#getHeaderString(String)
HttpHeaders#getRequestHeaders()
HttpHeaders#getHeaderString(String)
如果您需要标准 HTTP header 的值,请考虑使用 constants available in the HttpHeaders
API:
// Get the value of the Authorization header
String authorizationHeader = httpHeaders.getHeaderString(HttpHeaders.AUTHORIZATION);
有关上下文类型的更多详细信息,请参阅 Apache CXF documentation。