467,161 Members | 974 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Having problem in org.apache.commons.httpclient.methods.PostMethod?? ??

Hi all,
I am not able to login a site using the following code,
can anyone suggest me the right way?
There is no any https connection.


HttpClient client=new HttpClient();
client.getParams().setCookiePolicy(CookiePolicy.BR OWSER_COMPATIBILITY);

String userAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
String connection="Keep-Alive";

PostMethod postMethod = new PostMethod("url");
postMethod.addRequestHeader("User-Agent",userAgent );
postMethod.addRequestHeader("Connection", connection);
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
connectionManager.getParams().setConnectionTimeout (8000);

NameValuePair[] nameValue =new NameValuePair[3];
nameValue[0]=new NameValuePair("username","xxxxx");
nameValue[1]=new NameValuePair("password","xxxxx");
nameValue[2]=new NameValuePair("submit1","OK");
postMethod.setRequestBody(nameValue);
int status=client.executeMethod(postMethod);
StringTokenizer st1 =
new StringTokenizer(postMethod.getResponseBodyAsString ());


regards,
sundar
Feb 7 '08 #1
  • viewed: 3519
Share:

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Leo | last post: by
1 post views Thread by mirandacascade@yahoo.com | last post: by
5 posts views Thread by e2point@yahoo.com | last post: by
1 post views Thread by Carmen Sei | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.