[英]Can I make my own header field to be used by me and the clients visiting a web-app?
雖然我使用了一些標題字段,例如:
X-AppEngine-Country
X-AppEngine-City
( X
表示它們是非標准的標頭字段。)我在思考如何實現/設置自己的Http標頭字段以供其客戶端使用? 上面的標頭字段定義為供google appengine上托管的網絡應用使用。 〜 參考
從您的問題中我不確定您是否要強制客戶端向您發送這些自定義標頭或在服務器的響應中設置這些自定義標頭。 如果您使用的是使用JAX-RS(Jersey)的Java實現的REST API,那么從請求中獲取標頭或在響應上設置標頭就非常簡單。 下面的示例顯示了兩者。
@GET
public Response getClientMessage(@Context HttpContext context) {
// fetch the header values into a multi valued map
MultivaluedMap<String, String> headerMap = context.getRequest().getRequestHeaders();
// If the required headers are not found throw a bad request
// throw new WebApplicationException(Status.BAD_REQUEST);
// Setting the headers on the response
return Response.ok()
.header("X-AppEngine-Country", "US")
.header("X-AppEngine-City", "California").build();
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.