rest-assured - 无法使用 REST Assured 生成 Auth 令牌
问题描述
我正在尝试为我在本地机器上托管的 API 生成访问令牌。我可以使用 Postman 检索访问令牌。但我无法使用 RestAssured 做同样的事情。
下面是我为此编写的代码片段。
Response authentication = RestAssured.given().auth()
.basic("admin", "password123").header("content-type", "application/json")
.when()
.post("http://localhost:3001/auth/");
回复 :
{"reason":"Bad credentials}
如果我遗漏了任何内容,请帮助我弄清楚这一点。
解决方案
Response authentication = RestAssured.given().auth().preemptive() .basic("admin","password123") .header("content-type", "application/json") .when().post("http://localhost:3001/auth");
https://github.com/rest-assured/rest-assured/wiki/Usage#basic-authentication
推荐阅读
- javascript - Vuejs如何用i18翻译工作日
- java - 其他类的参考
- javascript - 动态图层组传单
- php - 在 Grav admin 中获取页面的后代
- aws-cdk - 将 CDK 导出到 cloudformation 模板 -python
- node.js - server.js 中定义的变量,但模板给出错误“未定义”
- typescript - 升级到 Mongoose 5.12,现在我无法使用 $push 运算符执行 findOneAndUpdate
- if-statement - 在批处理文件中使用用户输入 if 语句来确认输入并让它保存一个持久变量
- angular - 预期的函数是被调用的,但其中的任何函数都不会被调用
- javascript - 是否可以将 Object.create 与私有类方法一起使用?