Rajat,

Try this instead

HttpClient client = new HttpClient()
PostMethod post = new PostMethod("http://10.2.3.133:9090/jsp/index.jsp";);
NameValuePair userid   = new NameValuePair("userName", "root");
NameValuePair password = new NameValuePair("password", "public");
NameValuePair hidden   = new NameValuePair("requestfrom", "loginPage");
post.setRequestBody(
  new NameValuePair[] {hidden, userid, password});

Oleg

On Thu, 2005-05-12 at 14:25 -0400, Rajat Sharma wrote:
> Folks, I urgently need this. Any idea how to get this going ? Anyone?
> 
> -----Original Message-----
> From: Rajat Sharma 
> Sent: Thursday, May 12, 2005 11:00 AM
> To: '[email protected]'
> Subject: HttpClient: Cannot Login into a website. Authentication Issue
> 
> 
> Hi all,
> 
> I am trying to login into a webpage. Webserver is Apace Webserver and issue 
> is that I am not able to login into this webpage using httpclient.
> 
> The aim is to retrieve some data after I am able to log in.
> 
> Here is the WebPage html file and my code which is trying to access it. 
> 
> The response I get back is code 200, but it only says "Please try again" 
> 
> Any help is appreciated. 
> Regards
> 
> ------------------HTML FILE---------------------------------------
> <HTML>
> <HEAD>
> <TITLE> DOEMS  Version 3.0 </TITLE>
> <LINK REL=STYLESHEET TYPE="text/css" HREF="../template/nmshtmlui.css">
> <SCRIPT LANGUAGE="JavaScript1.2" SRC="../template/validation.js"></SCRIPT>
> <script>
> function validate(){
>       var userName = document.loginForm.userName.value;
>       var password = document.loginForm.password.value;
>       userName = trimAll(userName);
>       password = trimAll(password);
>       if(userName.length==0){
>               alert("Please enter user name");
>               return false;
>       }
>       if(password.length==0){
>               alert("Please enter password");
>               return false;
>       }
>       return true;
> }
> function init(){
>       document.loginForm.userName.focus();
> }
> 
> function showHelp(helpUrl){
>       window.open(helpUrl, 'nmshelp', 
> 'dependent=yes,screenX=200,screenY=300,titlebar=yes,resizable=yes');
> }
> </script>
> </HEAD>
> <BODY onLoad="init()">
>  
> <p align="center"><img border="0" src="../images/banner.jpg" width="700" 
> height="150"></p>
> 
> <form method=post target="_parent" name="loginForm" onSubmit="return 
> validate()"
> 
>               action="/jsp/index.jsp">
>       
>       <p align="center"> <font class="greenFont">Welcome! Please enter your 
> user name and password and login</font> </p> 
> <CENTER>
> <table border="0" width="428" cellspacing="0" cellpadding="0">
> <tr>
>       <td align="right">
>       <font face="Arial" size="2"><B>User Name &nbsp;</B></font>
>       </td>
>       <td aligh="left"> 
>       <input type="text" name="userName" size=20>
>       </td>
> </tr>
> <tr>
>       <td align="right">
>       <font face="Arial" size="2"><B>Password &nbsp;</B></font>
>       </td>
>       <td align="left">
>       <input type="password" name="password" size=20>
>       </td>
> </tr>
> </table>
> <input type="hidden" name="requestfrom" value="loginPage">
> 
> <br><br>
> 
> <blockquote>
> <p align="center"> 
> <font face="Arial" size="2"> 
>       <INPUT TYPE="SUBMIT" NAME="htmlui" VALUE="Login">
>       <!--input type="image" src="../images/HTMLUIButton.png" name="htmlui" 
> value="HTML UI"-->
>       &nbsp;&nbsp;&nbsp; 
>       <input type="hidden" name="requestfrom" value="loginPage">
>       <!--INPUT TYPE="SUBMIT" NAME="javaui" VALUE="JAVA UI"-->
>       <!--input type="image" src="../images/JAVAUIButton.png" name="javaui" 
> value="JAVA UI"-->
>       &nbsp;&nbsp;&nbsp;
>       <!--img border="0" src="../images/HELP.png" width="94" height="39"-->
>       <input type=button name="Help" value="Help" 
> onClick="showHelp('../WebHelp/context_sensitive/Output/wwhelp/wwhimpl/js/html/wwhelp.htm')">
> </font></p>
> </blockquote>
> 
> </CENTER>
> </form>
> </BODY>
> </HTML>
> ------------------HTML FILE---------------------------------------
> 
> <-------------------my Code--------------------------------------->
> client = new HttpClient();
>     PostMethod post = new PostMethod("http://10.2.3.133:9090/";);
>     
>       NameValuePair target   = new NameValuePair("target", "_parent");
>   NameValuePair action   = new NameValuePair("action", "/jsp/index.jsp");
>           NameValuePair url      = new NameValuePair("url", "/index.html");
>         NameValuePair userid   = new NameValuePair("loginForm.userName", 
> "root");
>         NameValuePair password = new NameValuePair("loginForm.userName", 
> "public");
>         post.setRequestBody(
>           new NameValuePair[] {target,action, url, userid, password});
> 
>     int status1;
>   
>        try {
>    
>     status1 = client.executeMethod(post);
> 
>    
> 
> 
> 
>       System.out.println("Status is Post:" + status1 + ":Body is:\n" +
>                          post.getResponseBodyAsString());
>     }
>     catch (Exception e) {
>       System.out.println("Problem here");
>     }
> 
> 
>    
>        System.out.println("Login form post: " + 
> post.getStatusLine().toString());
>    
>        post.releaseConnection();
> <-----------------END--my Code--------------------------------------->
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to