我使用以下代码验证google id令牌。它总是给我以下错误。但是使用相同的标题我可以在POST MAN工具中进行验证。请帮我解决这个问题。
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service =
client.resource("https://www.googleapis.com/oauth2/v3/userinfo");
try {
ClientResponse response = service.header("Authorization",
"Bearer ya29.Glt6BGkbIzLEjeeQ5Q8O51Jh7-PFD3hVLM7PORixSTVFY-
iduKE8HmK8KMtzYz-
yJ9rUqo_xY9yVKl5b6CAiTNAtFErb0bZJB3vX6vPZVRPwbY6kVCIDbukDc9FA")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept",
"Accept=text/html,application/xhtml+xml,
application/xml;q=0.9,*/*;q=0.8").get(ClientResponse.class);
} catch (Exception e) {
e.printStackTrace();
}
错误:
线程“main”中的异常 com.sun.jersey.api.client.UniformInterfaceException:GET https://www.googleapis.com/oauth2/v3/userinfo返回了回复状态 401未经授权