我正在尝试对我的一个应用程序使用放心,但问题是我无法进行身份验证。
以下是我正在尝试的代码
baseURI = "http://localhost:8080/api";
given()
.auth().form("admin", "admin", new FormAuthConfig("/authentication/", "j_username", "j_password"))
.when()
.get("/formAuth")
.then()
.log().all()
.statusCode(200);
我也尝试了以下选项, 以下代码和以上代码都没有解决 401 错误
form("admin", "admin", new FormAuthConfig("/", "j_username", "j_password"))
以下选项不起作用,显示无法解析登录页面。检查登录页面上的错误或指定 FormAuthConfig。错误
.auth().form("admin", "admin", formAuthConfig().withAutoDetectionOfCsrf())
以下是表格的代码
<form class="form ng-pristine ng-valid" role="form" ng-submit="login($event)">
<div class="form-group">
<label for="username" translate="global.form.username" class="ng-scope">Login</label>
<input type="text" class="form-control ng-pristine ng-valid ng-touched" id="username" placeholder="Your login" ng-model="username" autocomplete="off">
</div>
<div class="form-group">
<label for="password" translate="login.form.password" class="ng-scope">Password</label>
<input type="password" class="form-control ng-pristine ng-untouched ng-valid" id="password" placeholder="Your password" ng-model="password">
</div>
<div class="form-group">
<label for="rememberMe">
<input type="checkbox" id="rememberMe" ng-model="rememberMe" checked="" class="ng-pristine ng-untouched ng-valid">
<span translate="login.form.rememberme" class="ng-scope">Automatic Login</span>
</label>
</div>
<button type="submit" class="btn btn-primary ng-scope" translate="login.form.button">Authenticate</button>
</form>
以下是使用PostMan的捕获输出
URL: http://localhost:8080/api/authentication?cacheBuster=1485280599118
parameter: j_username:admin
j_password:admin