hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Krugler <kkrugler_li...@transpac.com>
Subject Re: Logging into a website issues with 4.0.1
Date Mon, 15 Feb 2010 16:36:56 GMT
In the automated login, I don't see the POST parameters:

txtUserName=myUserName&txtPassword=myPassWord

-- Ken

On Feb 15, 2010, at 7:36am, Robert Stone wrote:

> *Thanks to Jeff* for getting me on my way to figuring this issue  
> out. I took
> two wireshark logs to see what the differences are between the  
> automated
> login and the manual login just as he suggested. The text of the  
> wireshark
> logs are as follows.
>
> The Manual Login:
> -----------------------------------------------------------------------------------------------------------------------------
>
> POST /div/login HTTP/1.1
> Host: my.website.com:8080
> Connection: keep-alive
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
> AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.78 Safari/532.5
> Referer: http://my.website.com:8080/div/login
> Content-Length: 38
> Cache-Control: max-age=0
> Origin: http://my.website.com:8080
> Content-Type: application/x-www-form-urlencoded
> Accept:
> application/xml,application/xhtml+xml,text/html;q=0.9,text/ 
> plain;q=0.8,image/png,*/*;q=0.5
> Accept-Encoding: gzip,deflate,sdch
> Cookie: JSESSIONID=AF810830BBC3D8869D70178E73239217
> Accept-Language: en-US,en;q=0.8
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
>
> txtUserName=myUserName&txtPassword=myPassWordHTTP/1.1 302 Moved  
> Temporarily
> Server: Apache-Coyote/1.1
> Location: http://my.website.com:8080/div/
> Content-Length: 0
> Date: Fri, 12 Feb 2010 01:52:30 GMT
>
> ------------------------------------------------------------------------------------------------------------------------------------
> The Automated Login
> -----------------------------------------------------------------------------------------------------------------------------------
>
> POST /div/login.jsp?txtUserName=myUserName&txtPassword=myPassWord  
> HTTP/1.1
> Content-Length: 0
> Host: my.website.com:8080
> Connection: Keep-Alive
> User-Agent: Apache-HttpClient/4.0.1 (java 1.5)
>
> HTTP/1.1 200 OK
> Server: Apache-Coyote/1.1
> Set-Cookie: JSESSIONID=9563FDBAA69961D49B607C63383C5F7A; Path=/div
> Cache-Control: no-cache, must-revalidate
> Expires: 0
> Date: Fri, 12 Feb 2010 17:09:24 GMT
> Content-Type: text/xml;charset=UTF-8
> Content-Length: 3648
>
> ----------------------------------------------------------------------------------------------------
>
> As one can clearly see the Manual Login contains far much more  
> information
> in the Packet. I have no idea how to include this information in the  
> request
> that I am sending from the http-client class I made. I looked for  
> methods
> with auto complete that would allow me to add this information  
> however I
> found nothing specific. Can anyone get me started on the road to  
> adding this
> information to my automated login's packet.
>
> Originally I attached my source code in a zip file to make the email  
> more
> readable however this mail list doesn't seem to allow attachments so  
> here is
> the source code in text format.
>
> Sorry in advance if it is ugly or hard to read.
>
> First the Java class
> -----------------------------------------------------------------------------------'
>
> import java.io.IOException;
> import java.net.URI;
> import java.net.URISyntaxException;
> import java.util.ArrayList;
> import java.util.List;
> import org.apache.http.HttpEntity;
> import org.apache.http.HttpResponse;
> import org.apache.http.NameValuePair;
> import org.apache.http.client.ClientProtocolException;
> import org.apache.http.client.entity.UrlEncodedFormEntity;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.client.methods.HttpPost;
> import org.apache.http.client.utils.URIUtils;
> import org.apache.http.client.utils.URLEncodedUtils;
> import org.apache.http.cookie.Cookie;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.apache.http.message.BasicNameValuePair;
> import org.apache.http.protocol.BasicHttpContext;
> import org.apache.http.protocol.HTTP;
> import org.apache.http.protocol.HttpContext;
> import org.apache.http.util.EntityUtils;
>
> /**
> * WebUtils This class contains basic Web Utilities used for logging  
> into
> and manipulating data
> * on a requested website.
> *
> * @author ME
> */
> public class WebUtils {
>
>
>        /**
>         * getPageSource This Method will return the source code of the
> requested page when given the
>         *   following parameters
>         *
>         * @return pageSource The source code of the requested page
>         */
>        public String getPageSource(){
>
>                  String pageSource = "";
>
>                  DefaultHttpClient httpclient = new  
> DefaultHttpClient();
>                  HttpContext localContext = new BasicHttpContext();
>
>
>                  List<NameValuePair> qparams = new
> ArrayList<NameValuePair>();
>                  qparams.add(new BasicNameValuePair("txtUserName",
> "myusername"));
>                  qparams.add(new BasicNameValuePair("txtPassword",
> "mypassword"));
>
>                  URI uri;
>                try {
>                        uri = URIUtils.createURI("http",  
> "my.website.com",
> 8080, "/div/login",
>                              URLEncodedUtils.format(qparams, "UTF-8"),
> null);
>
>                        HttpPost httppost = new HttpPost(uri);
>                        HttpResponse response =  
> httpclient.execute(httppost,
> localContext);
>             HttpEntity entity = response.getEntity();
>
>             List<Cookie> cookies =
> httpclient.getCookieStore().getCookies();
>
>                if (cookies.isEmpty()) {
>                    System.out.println("None");
>                } else {
>                    for (int i = 0; i < cookies.size(); i++) {
>                        System.out.println(i +" - " +
> cookies.get(i).toString());
>                    }
>                }
>
>            if (entity != null) {
>               long len = entity.getContentLength();
>               if (len != -1) {
>               pageSource = EntityUtils.toString(entity);
>
>               } else {
>               pageSource = "";
>               }
>            }
>
>                } catch (URISyntaxException e) {
>                        e.printStackTrace();
>                } catch (ClientProtocolException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (IOException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>                return pageSource;
>          }
> }
>
> The Form
> ------------------------------------------------------------------------------------------------------
>
> <div class="loginPanel">
>    <div class="container">
>        <div class="title">Login</div>
>        <form id="loginForm" class="loginForm" method="POST"
> action="/div/login">
>            <font class="portlet-msg-error"
>                 style="font-weight: bold; font-size: 10px;  
> color:#FF0000;
> text-align: center;"></font>
>            <table>
>                <tr>
>                    <td class="label">USERNAME:</td>
>                    <td><input
>                            value=""
>                            class="edit"
>                            id="txtUsernameLogin"
>                            name="txtUserName"
>                            type="text"/></td>
>                </tr>
>                <tr>
>                    <td class="label">PASSWORD:</td>
>                    <td><input
>                            value=""
>                            class="edit"
>                            name="txtPassword"
>                            type="password"/></td>
>                </tr>
>                <tr>
>                    <td colspan="2" align="center">
>                        <input type="checkbox" name="txtRemember"
> value="true" align="middle"/>
>                        Remember me on this computer
>                    </td>
>                </tr>
>                <tr>
>                    <td></td>
>                    <td class=""><input type="submit"
>                                        class="submit"
>                                        value="Login"
>                                        alt="Login"/></td>
>                </tr>
>            </table>
>        </form>
>    </div>
> </div>
>
> Any help will be greatly appreciated.
>
> Thanks,
>
> Robert

--------------------------------------------
Ken Krugler
+1 530-210-6378
http://bixolabs.com
e l a s t i c   w e b   m i n i n g





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message