这是我改装的界面
@Headers({
"Content-Type: application/json",
"Accept: application/json"
})
@GET("api/services/app/Profile/GetCurrentUserProfileForEdit")
Call<GetUserProfile> getUserProfile(@Header("Authorization") String authorization);
Call<GetUserProfile> call = guardRestManager.getServices().getUserProfile("Bearer"+"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjMiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZmFoYWQiLCJBc3BOZXQuSWRlbnRpdHkuU2VjdXJpdHlTdGFtcCI6ImZjZmVmZDUzLTVkNDgtNDQxYi1hNjA5LWZjOGZlZjk0NWZkMCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6ImQyMDQ3MjQ1OGUyNDRjNjE5ZmUwNmU4M2QzNDQ3MmQzIiwiaHR0cDovL3d3dy5hc3BuZXRib2lsZXJwbGF0ZS5jb20vaWRlbnRpdHkvY2xhaW1zL3RlbmFudElkIjoiMSIsInN1YiI6IjMiLCJqdGkiOiJiZjdlOTliYy0wNWE3LTRlNmQtOTY1YS1jMTNmZTg4YzQzODAiLCJpYXQiOjE1MTM2OTY0ODUsIm5iZiI6MTUxMzY5NjQ4NSwiZXhwIjoxNTEzNzgyODg1LCJpc3MiOiJFYXN5U2VjdXJlIiwiYXVkIjoiRWFzeVNlY3VyZSJ9.jnCOhK3Iu1_x5XBP9Kd5oMCYj2iDrElLA8baRYX1FpM");
在邮递员中,它给出了正确的答案。但在我的应用程序中它给了我:
响应{protocol = http / 1.1,code = 401,message = Unauthorized,url = http://192.168.0.121:503/api/services/app/Profile/GetCurrentUserProfileForEdit}
答案 0 :(得分:0)
确保Bearer与您的令牌值之间有空格。如下所示:
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwcm4iOiJhbmRyb2lkX3N5c3RlbV91c2VyIiwiX2lkIjoiNTljYTQ2ZjQxZTZiYmNmMmUzMWY2NDc4IiwibWVtYmVyc2hpcF9pZCI6Im5ldGQiLCJkb21haW5zIjpbeyJfaWQiOiI1OTM3YTk2ZDliZjc4ZjIyMDlmNTAxODkiLCJ1c2VycyI6W10sInVzZXJfZ3JvdXBzIjpbXSwicGVybWlzc2lvbnMiOlsicWFwLioiLCJjbXMuKiJdfV0sInBlcm1pc3Npb25zIjpbInFhcC4qIiwiY21zLioiXSwiZXhwIjoxNTEyNjU4MjY4LCJqdGkiOiI1YTI5NGU1NDFlNmJiY2NlOTBjNDZiYzkiLCJpYXQiOjE1MTI2NTY0Njh9.7_Hu0Sw0TFoaBL9zFQhRaoIu8BBkfEo6GCikseO3r5E
当我在我的情况下删除那个空格时,它也给了我401状态代码。这可能是你的问题。
答案 1 :(得分:0)
在Bearer之后添加空格。 替换这个:
(&#34;承载&#34; +&#34; eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjMiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZmFoYWQiLCJBc3BOZXQuSWRlbnRpdHkuU2VjdXJpdHlTdGFtcCI6ImZjZmVmZDUzLTVkNDgtNDQxYi1hNjA5LWZjOGZlZjk0NWZkMCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6ImQyMDQ3MjQ1OGUyNDRjNjE5ZmUwNmU4M2QzNDQ3MmQzIiwiaHR0cDovL3d3dy5h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FzeVNlY3VyZSJ9.jnCOhK3Iu1_x5XBP9Kd5oMCYj2iDrElLA8baRYX1FpM&#34)
持票人和令牌之间应该有一个空格
答案 2 :(得分:0)
我以前遇到过这个问题。解决方案是在令牌类型(载体)和令牌之间添加空格。