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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsuns82
    New Member
    • Mar 2007
    • 58

    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.getParam s().setCookiePo licy(CookiePoli cy.BROWSER_COMP ATIBILITY);

    String userAgent="Mozi lla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    String connection="Kee p-Alive";

    PostMethod postMethod = new PostMethod("url ");
    postMethod.addR equestHeader("U ser-Agent",userAgen t );
    postMethod.addR equestHeader("C onnection", connection);
    HttpConnectionM anager connectionManag er = client.getHttpC onnectionManage r();
    connectionManag er.getParams(). setConnectionTi meout(8000);

    NameValuePair[] nameValue =new NameValuePair[3];
    nameValue[0]=new NameValuePair(" username","xxxx x");
    nameValue[1]=new NameValuePair(" password","xxxx x");
    nameValue[2]=new NameValuePair(" submit1","OK");
    postMethod.setR equestBody(name Value);
    int status=client.e xecuteMethod(po stMethod);
    StringTokenizer st1 =
    new StringTokenizer (postMethod.get ResponseBodyAsS tring());


    regards,
    sundar
Working...