예제 #1
0
 private void setCookie(WebResponse rs) {
   String[] cookies = rs.getHeaderFields("set-cookie");
   for (String cookie : cookies) {
     String firstCookie = cookie.split(";")[0];
     String[] cookieStr = firstCookie.split("=");
     if (cookieStr.length == 2) {
       wc.putCookie(cookieStr[0], cookieStr[1]);
     } else {
       wc.putCookie(cookieStr[0], "");
     }
   }
 }
예제 #2
0
 public static void doJoinGame(WebConversation client) throws Exception {
   System.out.println("Joining game...");
   WebResponse response = client.getResponse("http://127.0.0.1:8080/games/euchre?action=joinGame");
   for (String name : response.getHeaderFieldNames()) {
     System.out.println(
         "header: name=" + name + ", value=" + Arrays.toString(response.getHeaderFields(name)));
   }
   System.out.println("response code=" + response.getResponseCode());
   for (String name : response.getNewCookieNames()) {
     System.out.println(
         "new cookie: name=" + name + ", value=" + response.getNewCookieValue(name));
   }
   System.out.println("text=" + response.getText());
 }
예제 #3
0
 public static void doAnonymousLogin(WebConversation client, String nickname) throws Exception {
   System.out.println("Logging in anonymously...");
   PostMethodWebRequest request =
       new PostMethodWebRequest("http://127.0.0.1:8080/games/anonLogin");
   request.setParameter("nickname", nickname);
   WebResponse response = client.getResponse(request);
   for (String name : response.getHeaderFieldNames()) {
     System.out.println(
         "header: name=" + name + ", value=" + Arrays.toString(response.getHeaderFields(name)));
   }
   System.out.println("response code=" + response.getResponseCode());
   for (String name : response.getNewCookieNames()) {
     System.out.println(
         "new cookie: name=" + name + ", value=" + response.getNewCookieValue(name));
   }
   System.out.println("text=" + response.getText());
 }