Dear friends

I would like to ask about using Apache httpclient for retrieving knowledge
from some online databases through forms.
My problem is that there is one webpage that contains two forms on one page
and I want to send only the second form, not the first one! Both forms have
a search box and submit button.
I thought that it might be enought to leave the NameValuePair parameters for
the first form just blank. But the code below does not work.

Thanks for helping.


import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
 
public class SubmitHttpForm {
 
    private static String url =
         "http://www.website.com";;
 
    public static void main(String[] args) {
 
        //Instantiate an HttpClient
        HttpClient client = new HttpClient(new
MultiThreadedHttpConnectionManager());
 
        //Instantiate a GET HTTP method
        HttpMethod method = new GetMethod(url);
 
        //Define name-value pairs to set into the QueryString
        NameValuePair nvp1= new NameValuePair("search","");
        NameValuePair nvp2= new NameValuePair("submit","");
       NameValuePair nvp3= new NameValuePair("search","route");
       NameValuePair nvp3= new NameValuePair("submit","go");
 
      method.setQueryString(new NameValuePair[]{nvp1,nvp2, nvp3, nvp4});
        
        try{
            int statusCode = client.executeMethod(method);
 
            System.out.println("QueryString>>> "+method.getQueryString());
            System.out.println("Status Text>>>"
                  +HttpStatus.getStatusText(statusCode));
 
            //Get data as a String
            System.out.println(method.getResponseBodyAsString());
 
            //OR as a byte array
            byte [] res  = method.getResponseBody();
 
            //write to file
            FileOutputStream fos= new
FileOutputStream("./output/donepage.html");
            fos.write(res);
 
            //release connection
            method.releaseConnection();
        }
        catch(IOException e) {
            e.printStackTrace();
        }
    }
}

 

-- 
View this message in context: 
http://www.nabble.com/How-to-handle-two-forms-on-one-page-with-apache-httpclient-tp19991354p19991354.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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

Reply via email to