如何解决请放心 - 无法重复使用响应令牌
我需要创建一个 Rest 测试请求。 我创建了一些简单的测试,登录,创建帐户,... 但现在对我来说更复杂了。
我的请求示例如下所示:
JSONObject childJSON = new JSONObject();
childJSON.put("email","user@yahoo.com");
childJSON.put("password","1asdaasx");
JSONObject request = new JSONObject();
request.put("user",childJSON);
String token = given().
auth().
basic("login","password").
header("Content-Type","application/json").
body(request).
when().
post("https://BASEuri.com/api/users/login").
then().
statusCode(200).
.log().all()
.extract().path("user.token").toString();
}
回复
{ "user": { "username": "user","email": "user@yahoo.com","token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwYWNmogMzNjkzMTg1OWE1ZWVkNjQzMSIsInVsdcalIjoicGkyc3FyMiIsImV4cCI6MTYyNzY3ODE4MiwiaWF0IjoxNjIyNDk0MTgyfQ.a4kfaLbQgO0y-8MRx69O4SOSasdw4XCkMvhetDkG3w","bio": "123","image": "" } }
API 规范
更新用户 PUT /api/user 示例 { "user":{ "email": "me@me.com","bio": "我喜欢音乐","图像": "https://i.stack.imgur.com/qwe.jpg" } }
第二个请求
JSONObject childJSONSub = new JSONObject();
childJSONSub.put("email","user@yahoo.com");
childJSONSub.put("bio","My New Bio");
childJSONSub.put("image","https://i.stack.imgur.com/sad3.jpg");
JSONObject requestSub = new JSONObject();
requestSub.put("user",childJSONSub);
given().
auth().
basic("login","password").
header("Content-Type","application/json").
queryParam("Authorization",token).
body(requestSub).
when().
put("https://BASEuri.com/api/user").
then().
log().all();
但答案是这样的:
"errors": {
"message": "No authorization token was found","error": {
"name": "UnauthorizedError","message": "No authorization token was found","code": "credentials_required","status": 401,"inner": {
"message": "No authorization token was found"
}
}
}
有什么建议吗? 我已经尝试了多种令牌解决方案,但总是得到相同的结果。
解决方法
您需要一个访问令牌才能被授权访问此功能
此访问令牌根据 API 以不同方式提供
可能有一些端点可以获取令牌
为了给您提供更多帮助,我需要有关问题的更多信息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。