Jersey HTTP response 200 OK but returning content wrong (username/password incorrect)

六眼飞鱼酱① 提交于 2019-12-24 12:24:21

问题


I was wondering if I wrote the Jersey client side code in the correct way.

The log-in page is supposed to redirect to main page after correct username and password input, with server side returning an empty string (""). If either is incorrect, server side code returns "Username or Password are incorrect".

The page functionality worked well but when I was testing using my client side code using a correct pair of username and password, it returns "Username or Password are incorrect", with response returning 200OK. Below is my client side code.

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));
}

I suspect the username and password were not submitted in correct input positions required in HTML file. Below is the block of my HTML file.

 <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>

回答1:


Use login instead of username for the post data.



来源:https://stackoverflow.com/questions/31681218/jersey-http-response-200-ok-but-returning-content-wrong-username-password-incor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!