hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From afmustac <afmus...@yahoo.com>
Subject help with httpclient methods please!!!!
Date Tue, 31 Jan 2006 22:17:23 GMT
 Hello everyone,

I am new to httpclient, and I tried to use it in many ways to practice...Right now, I am 
working on a project to submit my data to  one of the website,which I have already an account.
I can successfully login to the site.
Like below:
PostMethod post = new PostMethod(LOGON_SITE + "/login");
            post.setRequestBody(data);           
            int status = client.executeMethod(post);

            /**
             * Check to see if there is any redirections or not
             */
            locationHeader =  post.getResponseHeader("location");
            post.releaseConnection();
            if (locationHeader != null) {
                redirectLocation = locationHeader.getValue();

                System.out.println("<Connotea>After Login>>Redirect:"
                        + redirectLocation + "\n");                                
                GetMethod getRedirectLogon = new GetMethod(redirectLocation);
                 getRedirectLogon.setFollowRedirects(true);
                status = client.executeMethod(getRedirectLogon);
                getRedirectLogon.releaseConnection();
            }.

Right after logged-in, I need to get my form page by using GetMethod, and then I need to use
PostMethod to post my data.And, there is a redirection again, so I need to use GetMethod again.
When I do this actually it works for submitting one record..but if I do this in a loop for
posting more than one record, it just shows my last record in my library on the web site..it
kind of ignores or does not submit successfully the preious records.My code for it as below:

GetMethod getAddForm = new GetMethod(LOGON_SITE+"/add");
                status =  client.executeMethod(getAddForm);

PostMethod postAddForm = new PostMethod(LOGON_SITE+"/add");
                postAddForm.setRequestBody(ref);
                status = client.executeMethod(postAddForm);

locationHeader = postAddForm.getResponseHeader("location");
                postAddForm.releaseConnection();
                if (locationHeader != null) {
                    redirectLocation = locationHeader.getValue();
                    System.out.println("Redirect after posting:"
                             + redirectLocation + "\n");
                    GetMethod getRedirectPostForm = new GetMethod(
                            redirectLocation);
                    getRedirectPostForm.setFollowRedirects(true);
                    status = client.executeMethod(getRedirectPostForm);
getRedirectPostForm.releaseConnection();
                }


Could you please help me? I really do appreciate any help...thank you so much...

--teo


		
---------------------------------
 
 What are the most popular cars? Find out at Yahoo! Autos 
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message