Java Jersey HTTP响应200正常,但返回内容错误(用户名/密码不正确)
我想知道我是否以正确的方式编写了Jersey客户端代码 登录页面应该在正确输入用户名和密码后重定向到主页,服务器端返回空字符串(Java Jersey HTTP响应200正常,但返回内容错误(用户名/密码不正确),java,html,rest,http,jersey,Java,Html,Rest,Http,Jersey,我想知道我是否以正确的方式编写了Jersey客户端代码 登录页面应该在正确输入用户名和密码后重定向到主页,服务器端返回空字符串(“”)。如果其中一个不正确,服务器端代码返回“用户名或密码不正确” 页面功能运行良好,但当我使用正确的用户名和密码对使用客户端代码进行测试时,它返回“用户名或密码不正确”,响应返回200OK。下面是我的客户端代码 public static void main(String[] args){ ClientConfig config = new ClientCon
“”
)。如果其中一个不正确,服务器端代码返回“用户名或密码不正确”
页面功能运行良好,但当我使用正确的用户名和密码对使用客户端代码进行测试时,它返回“用户名或密码不正确”
,响应返回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文件块
<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>
如需更多信息,请联系服务台
信息。
请登录:
使用登录
而不是用户名
获取帖子数据。谢谢。这是我刚才注意到的一个问题。但在将“用户名”改为“登录”后,问题仍然存在。我在考虑我的客户端java代码中是否存在“表单”问题。这是否适用于curl?也许j_security_check javascript函数有点神奇……我如何检查它是否与curl一起工作?gradle(我用gradle构建)命令提供java.lang.NullPointerException
尝试使用curl或任何其他可以执行HTTP的工具执行post。还有一些浏览器插件也可以完成这项工作。我在命令行中使用gradle构建项目。我得到了一个错误java.lang.NullPointerException
,然后是com.google.common.base.CharMatcher.trimTrailingFrom(CharMatcher.java:1242)
。那会是什么?