如何使用会话缓存使用groovy / java在url上触发操作

时间:2014-09-21 06:39:12

标签: java groovy

我想在登录网站后使用会话缓存来触发一些操作。 下面我在groovy中编写了代码。 我坚持将会话缓存传递给我的行动。

{
   HttpResponse httpResponse=null;
   String responseString = null;
   String appUrl = "test.com";
   String actionName = "testUsers.action";

   try {

      httpPost = new HttpPost(appUrl + "/" + actionName);
      //System.out.println("postmethod\t" + httpPost.getURI());

      nameValuePair.add(new BasicNameValuePair("j_password", "test"));
      nameValuePair.add(new BasicNameValuePair("j_username","test@test.com"));
      nameValuePair.add(new BasicNameValuePair("login", "Login"));

      httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
      httpResponse = httpClient.execute(httpPost);
      //String server = httpResponse.getFirstHeader("Set-Cookie").getValue();
      //System.out.println("httpResponse="+httpResponse);   
      //httpResponse.addCookie(server); 
      responseString = IOUtils.toString(httpResponse.getEntity().getContent());

    } finally {
      httpPost.abort();
    }
}

0 个答案:

没有答案