我想知道我是否以正确的方式编写了 Jersey 客户端代码。
登录页面应该在输入正确的用户名和密码后重定向到主页面,服务器端返回一个空字符串 (""
)。如果其中任何一个不正确,服务器端代码将返回 "Username or Password are incorrect"
。
页面功能运行良好,但当我使用正确的用户名和密码对使用我的客户端代码进行测试时,它返回 “用户名或密码不正确”
,响应返回 200OK。下面是我的客户端代码。
public static void main(String[] args){
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target("http://localhost:8080
/qa-automation-console").path("authenticate");
Form form = new Form();
form.param("username", "username");
form.param("password", "password");
Response response = target.request().post(Entity.form(form));
//The response was 200OK.
System.out.println(response.readEntity(String.class));
}
我怀疑用户名和密码没有按照 HTML 文件要求的正确输入位置提交。下面是我的 HTML 文件的 block 。
<form name="j_security_form" method="post" action="j_security_check">
<td colspan="3" class="body"><strong>Please contact the service desk for additional
information.</strong></td>
<td colspan="3" align="left"><p class="errorTitle"></p></td>
<span>
<td colspan="3" align="left"><p class="subTitle1">Please log in:</p></td>
<input class="input-small input-block" ng-model="username" placeholder="Username"
id="top_login" name="login" value="" autocomplete="on" type="text"></input>
<td colspan="3" align="left"><p class="space"></p></td>
<input class="input-small input-block" ng-model="password" placeholder="Password"
id="top_password" name="password" value="" autocomplete="on" type="password"></input>
</span>
<li style="display: none;" id="message" class="login-fail hidden">Wrong username
or password</li>
</form>
最佳答案
使用 login
而不是 username
作为发布数据。
关于java - Jersey HTTP 响应 200 OK 但返回内容错误(用户名/密码不正确),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31681218/