我正在尝试通过邮递员请求的标头发送身份验证令牌(将来通过JavaScript发送),但我在某处弄错了 .
这是Java中的REST方法:
@GET
@Produces("text/plain")
@Consumes("text/plain")
@RequestMapping(value = "/products/{id}", method = RequestMethod.GET)
public ResponseList getProducts(@PathVariable("id") String id, @HeaderParam("Authorization") String token) throws JSONException, IOException {
System.out.println( "id" + id);
System.out.println( "token" + token);
[...]
return products;
}
所以,当我使用REST方法时,我会正确获取id:
http://localhost:8080/service/products/Gold作为GET . id在system.out中正确显示为Gold .
但我正在尝试使用Postman在 Headers 上发送“授权”值,并且'token'在system.out中返回null .
我是否错误地使用@HeaderParam,或者可能在Postman本身上不正确地设置 Headers ?
谢谢!
1 回答
您是否尝试过使用@RequestHeader?