hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rajapandian R <r.rajapand...@verchaska.com>
Subject Re: Problem in downloading a page
Date Sat, 11 Feb 2006 07:24:51 GMT
Dear Roland
> 1. did you execute a GET before the POST to establish a session?
>   
yes the initial request was Get request
> 2. are session cookies obtained with the GET sent back as expected?
>    Play around with cookie policies and "single-cookie-header", as
>    mentioned in the cookie guide.
>   
I didnt handled any cookie policies, but checked the Cookie request 
header of the second and third request, it was ok.
> 3. are you sure you send all required parameters with the POST?
>    In the same format as indicated by the <form> in the web page?
>    (multipart vs. URL-encoded)
>   
yes i am sure, since i use ie http analyser and get the required parameters
> 4. try sending a User-Agent header with an IE or Mozilla value
>
> 5. try sending a Referer-Header (spelling intentional)
>
> 6. get a network monitor, grab the request sent by the browser,
>    then compare the one generated by HttpClient line-by-line
>   
 

> 7. if you have problems creating a request identical to the one
>    generated by the browser, post a *detailed* description of
>    what you want to send and what is generated by HttpClient
>   

i use ie http analyser and get the required informations and i set all 
the request headers and i give the required  form values .
i checked the cookie values,every thing is right,  the response is 200 
ok,but the content length is zero.i have pasted the code below.
please have a look and suggest me some  ideas.


--------------------------------------------------------------------------------------------------------------
import java.awt.HeadlessException;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.TraceMethod;
public class GoAirAvailability {
    public static void main(String[] args) throws IOException, 
HeadlessException {
        HttpClient client = new HttpClient();
        try{
               
            GetMethod homepage = new GetMethod("http://www.goair.in/");
           
            homepage.setRequestHeader("Request-Line","GET /HTTP/1.1");
            
homepage.setRequestHeader("Accept","image/gif,image/x-xbitmap, 
image/jpeg, 
image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,

application/msword,*/*");
            homepage.setRequestHeader("Accept-Language","en-us");
            homepage.setRequestHeader("Accept-Encoding","gzip,deflate");
            
homepage.setRequestHeader("User-Agent","Mozilla/4.0(compatible; MSIE 
6.0; Windows NT 5.1; SV1)");
            homepage.setRequestHeader("Host","www.goair.in");
            homepage.setRequestHeader("Connection","Keep-Alive");
           
           
           
           

           
            int statusCode0 = client.executeMethod(homepage);
            System.out.println("Search 
page::flykingfisher.biz"+homepage.getStatusLine());
           
           
            System.out.println("Response headers of request1 (home 
page)-----------------------------------------------");
            Header[] homepageres = homepage.getResponseHeaders();
             for (int i = 0; i < homepageres.length; i++) {
               
                 System.out.println(homepageres[i].toExternalForm());
               
            }
           
            
 System.out.println("--------------------------------------------------------------------------------------");
             
             PostMethod searchresult = new 
PostMethod("http://www.goair.in/besr_availability.aspx");
             
            
 searchresult.setRequestHeader("Request-Line","POST/besr_availability.aspx 
HTTP/1.1");
            
 searchresult.setRequestHeader("Accept","image/gif,image/x-xbitmap, 
image/jpeg, 
image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,

application/msword,*/*");
             searchresult.setRequestHeader("Referer","http://goair.in/");
             searchresult.setRequestHeader("Accept-Language","en-us");
            
 searchresult.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            
 searchresult.setRequestHeader("Accept-Encoding","gzip,deflate");
            
 searchresult.setRequestHeader("User-Agent","Mozilla/4.0(compatible; 
MSIE 6.0; Windows NT 5.1; SV1)");
             searchresult.setRequestHeader("Host","goair.in");
            //searchresult.setRequestHeader("Content-Length","551");
             searchresult.setRequestHeader("Connection","Keep-Alive");
             searchresult.setRequestHeader("Cache-Control","no-cache");
            
//searchresult.setRequestHeader("Cookie","ASP.NET_SessionId=wsdgmsbpbb5k3prikmg50c45");
             
             
             
                NameValuePair nvp1 = new 
NameValuePair("cboNationality","IN");
                NameValuePair nvp2 = new NameValuePair("hidRemote","");
                NameValuePair nvp3 = new 
NameValuePair("__EVENTTARGET","BE_SearchBar11:lnkSearch");
                NameValuePair nvp4 = new NameValuePair("rbRound","one");
                NameValuePair nvp5 = new NameValuePair("cboChild","0");
                NameValuePair nvp6 = new 
NameValuePair("__EVENTARGUMENT","");
                NameValuePair nvp7 = new NameValuePair("cboInfant","0");
                NameValuePair nvp8 = new NameValuePair("hidDestination","");
                NameValuePair nvp9 = new 
NameValuePair("__VIEWSTATE","dDwyODczMTEwMjk7dDw7bDxpPDE+Oz47bDx0PDtsPGk8Mz47PjtsPHQ8O2w8aTwwPjtpPDE+Oz47bDx0PHA8O3A8bDxvbmNsaWNrOz47bDxyZXR1cm4gdmFsaWRhdGVfU2VhcmNoKCk7Pj4+Ozs+O3Q8cDw7cDxsPG9uY2xpY2s7PjtsPHJldHVybiB2YWxpZGF0ZV9TZWFyY2goKTs+Pj47Oz47Pj47Pj47Pj47PjiegUxbAvWlc5Hrx0/8gVkHebp9");
                NameValuePair nvp10 = new NameValuePair("cboClass","3");
                NameValuePair nvp11 = new NameValuePair("hidRound","one");
                NameValuePair nvp12 = new 
NameValuePair("cbodepdayyear","3,2006");
                NameValuePair nvp13 = new NameValuePair("cboAdult","1");
                NameValuePair nvp14 = new NameValuePair("hidRetDate","");
                NameValuePair nvp15 = new 
NameValuePair("cboOrigin","GOI7");
                NameValuePair nvp16 = new NameValuePair("cbodepday","11");
                NameValuePair nvp17 = new NameValuePair("hidOrigin","");
                NameValuePair nvp18 = new 
NameValuePair("cboDestination","BOM1");
                //NameValuePair nvp19 = new 
NameValuePair("cbomonthyearret","3,2006");
               // NameValuePair nvp20 = new NameValuePair("cboretday","10");
               
                searchresult.setRequestBody(new 
NameValuePair[]{nvp1,nvp2,nvp3,nvp4,nvp5,nvp6,nvp7,nvp8,nvp9,nvp10,
                                
nvp11,nvp12,nvp13,nvp14,nvp15,nvp16,nvp17,nvp18});//,nvp19,nvp20
             
             
           
            /* 
searchresult.setRequestBody("__EVENTTARGET=BE_SearchBar11%3AlnkSearch&__EVENTARGUMENT=&__VIEWSTATE=dDwyODczMTEwMjk7dDw7bDxpPDE%2BOz47bDx0PDtsPGk8Mz47PjtsPHQ8O2w8aTwwPjtpPDE%2BOz47bDx0PHA8O3A8bDxvbmNsaWNrOz47bDxyZXR1cm4gdmFsaWRhdGVfU2VhcmNoKCk7Pj4%2BOzs%2BO3Q8cDw7cDxsPG9uY2xpY2s7PjtsPHJldHVybiB2YWxpZGF0ZV9TZWFyY2goKTs%2BPj47Oz47Pj47Pj47Pj47Pkx%2B1JMmXFaM8Kb85kapAZSVJvDx&"

+
                     
"rbRound=one&hidRound=one&hidRemote=&cboOrigin=GOI7&hidOrigin=&cboDestination=BOM1&hidDestination=&"

+
                     
"cbodepday=11&cbodepdayyear=3%2C2006&hidRetDate=&cboAdult=1&cboInfant=0&cboChild=0&cboClass=3&"

+
                     "cboNationality=IN");
             */
             int status1 = client.executeMethod(searchresult);
             
             System.out.println(searchresult.getResponseBodyAsString());
           
             System.out.println("Request headers of  request 
2-----------------------------------------------");
                Header[] searchresultreq =    
searchresult.getRequestHeaders();
                 for (int i = 0; i < searchresultreq.length; i++)
                 {
                   
                    
 System.out.println(searchresultreq[i].toExternalForm());
                   
                }
               
                
 System.out.println("--------------------------------------------------------------------------------------");
             
             System.out.println(searchresult.getRequestHeader("Cookie"));
             System.out.println("Search 
page::flykingfisher.biz"+homepage.getStatusLine());
               
               
                System.out.println("Response headers of request 
2-----------------------------------------------");
                Header[] searchresultres =    
searchresult.getResponseHeaders();
                 for (int i = 0; i < searchresultres.length; i++)
                 {
                   
                    
 System.out.println(searchresultres[i].toExternalForm());
                   
                }
               
                
 System.out.println("--------------------------------------------------------------------------------------");

             
                 GetMethod searchresultpage = new 
GetMethod("http://www.goair.in/Booking/BERP_Availability.aspx");
                 
                 
                 
               
                
 searchresultpage.setRequestHeader("Request-Line","GET/Booking/BERP_Availability.aspx 
HTTP/1.1");
                
 searchresultpage.setRequestHeader("Accept","image/gif,image/x-xbitmap, 
image/jpeg, 
image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,

application/msword,*/*");
                
 searchresultpage.setRequestHeader("Accept-Language","en-us");
                
 searchresultpage.setRequestHeader("Accept-Encoding","gzip,deflate");
                
 searchresultpage.setRequestHeader("User-Agent","Mozilla/4.0(compatible; 
MSIE 6.0; Windows NT 5.1; SV1)");
                 searchresultpage.setRequestHeader("Host","goair.in");
                
 searchresultpage.setRequestHeader("Connection","Keep-Alive");
                
//searchresultpage.setRequestHeader("Cookie","ASP.NET_SessionId=wsdgmsbpbb5k3prikmg50c45");
           
                                 
                 int finalstatus = client.executeMethod(searchresultpage);
                 
               
                
 System.out.println(searchresultpage.getRequestHeader("Cookie"));
                
 System.out.println(searchresultpage.getResponseBodyAsString());
                 
                 System.out.println("Response headers of request 2 
-----------------------------------------------");
                    Header[] searchresultpageres = 
searchresultpage.getResponseHeaders();
                     for (int i = 0; i < searchresultpageres.length;i++) {
                       
                        
 System.out.println(searchresultpageres[i].toExternalForm());
                       
                    }
                   
                    
 System.out.println("--------------------------------------------------------------------------------------");

                 
                     
             
             
        }
        catch(IOException e)
        {
            System.out.println(e);
        }
    }
   
}


regards
rajapandian.
       





---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message