无法移动到下一页http://indianvisa-bangladesh.nic.in/visa/Get_Appointment via httpClient 4.4

问题描述:

Hiii 更新2: 感谢4的帮助。 我现在得到了饼干,但我被困在同一页面上。 我添加了cookie作为标题与请求,但我得到了相同的页面作为响应。 不知道我做错了。 请指导我。无法移动到下一页http://indianvisa-bangladesh.nic.in/visa/Get_Appointment via httpClient 4.4

org.apache.http.impl.client.AbstractHttpClient httpclient = new org.apache.http.impl.client.DefaultHttpClient(); 
    try { 
     // Create a local instance of cookie store 
     CookieStore cookieStore = new BasicCookieStore(); 

     // Create local HTTP context 
     HttpContext localContext = new BasicHttpContext(); 
     // Bind custom cookie store to the local context 
     System.out.println("Binding Cookie from Cookie Store="+this.cookies); 
     String c=this.cookies.replaceAll("Set-Cookie: ", ""); 
     String c1=c.replaceAll(";path=/", ""); 
     System.out.println("c="+c1); 
     String []ar=c1.split("="); 
     System.out.println("a[0]="+ar[0]); 
     System.out.println("a[1]="+ar[1]); 
     BasicClientCookie cookie = new BasicClientCookie(ar[0], ar[1]); 
     cookie.setDomain("indianvisa-bangladesh.nic.in"); 
     cookie.setPath("/"); 
     cookieStore.addCookie(cookie); 
     httpclient.setCookieStore(cookieStore); 


     localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); 

     HttpGet httpget = new HttpGet("http://indianvisa-bangladesh.nic.in/visa/Get_Appointment"); 

     System.out.println("executing request " + httpget.getURI()); 

     // Pass local context as a parameter 
     HttpResponse response = httpclient.execute(httpget, localContext); 
     HttpEntity entity = response.getEntity(); 

     System.out.println("----------------------------------------"); 
     System.out.println(response.getStatusLine()); 
     if (entity != null) { 
      System.out.println("Response content length: " + entity.getContentLength()); 
     } 
     List<Cookie> cookies = cookieStore.getCookies(); 
     for (int i = 0; i < cookies.size(); i++) { 
      System.out.println("Local cookie: " + cookies.get(i)); 
     } 
     BufferedReader rd = new BufferedReader(
       new InputStreamReader(response.getEntity().getContent())); 
     StringBuffer result = new StringBuffer(); 
     String line = ""; 
     while ((line = rd.readLine()) != null) { 
      result.append(line); 
     } 
     System.out.println("Page contect="+result); 

     // Consume response content 
     EntityUtils.consume(entity); 

     System.out.println("----------------------------------------"); 

    } finally { 
     // When HttpClient instance is no longer needed, 
     // shut down the connection manager to ensure 
     // immediate deallocation of all system resources 
     //httpclient.getConnectionManager().shutdown(); 
    } 
+0

任何帮助将不胜感激!!!! – Rohit

+0

感谢您的帮助。我得到了饼干,但我无法移动到下一页不知道为什么。我提供了cookie作为标题与请求,但我仍然坚持在同一页。 – Rohit

+0

你正在做一个页面的请求,你得到的内容,我不明白你为什么期望另一个页面,或者你希望你的代码移动到另一个页面,你能解释你试图做什么来尝试帮助你因为你的代码没有试图移动到另一个页面 –

+0

我的意思是我没有得到内容,即使我正在提供cookie的contxt,它正在被重定向的地方,因为当我在浏览器中尝试这个,它的工作完美。 – Rohit