You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Lee Haw, Ong" <le...@commzgate.com> on 2002/06/17 12:33:41 UTC

OT: commons-user available?

Hi guys,

I'm terribly sorry to interrupt, but I can't find a commons-user list to
post my question to.

I'm using HttpClient to simulate a HTTP session with a web-based service,
which sends a couple cookies if the login attempt is successful. There's one
problem here. Through a local HTTP proxy log I can see that the cookies are
sent in server response. However when I do client.getState().getCookies(),
what I got is an empty array.

Can somone please point me to the right direction? I had attached my source
code together with this email. Much appreciated!


Thanks and regards,
Lee Haw

------------------------------------


import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

import java.net.*;
import java.io.*;

public class HttpTest {

 public static void main(String[] args) {
  HttpClient client = new HttpClient();
  String strURL = "/xgi-bin/www.xpedite.com.sg-r01/login";
  client.startSession("www.xpedite.com.sg", 80);

  PostMethod postMethod = new PostMethod(strURL);
        postMethod.setFollowRedirects(true);
  postMethod.addRequestHeader("Accept", "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*");
  postMethod.addRequestHeader("Referer",
"http://www.xpedite.com.sg/xweb/www.xpedite.com.sg-r01/login.html");
  postMethod.addRequestHeader("Accept-Language", "en-us");
  postMethod.addRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
  postMethod.addRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.0)");
  postMethod.addRequestHeader("Host", "www.xpedite.com.sg");
  postMethod.addRequestHeader("Content-Length", "177");
  postMethod.addRequestHeader("Pragma", "no-cache");
  postMethod.addRequestHeader("Connection", "keep-alive");
        postMethod.addParameter("success",
"/xweb/www.xpedite.com.sg-r01/welcome.html");
  postMethod.addParameter("failure",
"/xweb/www.xpedite.com.sg-r01/notloggedin.html");
        postMethod.addParameter("domain", "domain=.xpedite.com.sg");
  postMethod.addParameter("user", "****");
  postMethod.addParameter("password", "****");

  String response = null;
  try {
   int code = client.executeMethod(postMethod);
            System.out.println("HTTP status code is: " + code);
   response = postMethod.getResponseBodyAsString();
   System.out.println(response);
            HttpState state = client.getState();
            Cookie[] cookies = state.getCookies();
            for(int i = 0; i < cookies.length; i++) {
                System.out.println(cookies[i]);
            }
   client.endSession();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (HttpException e) {
   e.printStackTrace();
  }
 }

}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>