2016-09-17 9 views
0

Hiii 업데이트 2 : 감사합니다. 나는 지금 쿠키를 가지고 있지만 같은 페이지에 붙어 있습니다. 요청이있는 헤더로 쿠키를 추가했지만 응답과 동일한 페이지가 있습니다. 내가 잘못하고 있는지 모릅니다. 나를 안내하십시오.다음 페이지로 이동할 수 없습니다. httpClient를 통해 http://indianvisa-bangladesh.nic.in/visa/Get_Appointment를 방문하십시오. 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
+0

도움을 주셔서 감사합니다. 나는 쿠키를 얻었지만 다음 페이지로 넘어갈 수 없다. 왜 그런지 모르겠다. 요청과 함께 헤더로 쿠키를 제공했지만 여전히 같은 페이지에 머물러 있습니다. – Rohit

+0

페이지에 대한 요청을하고 있는데 콘텐트를 얻었습니다. 왜 다른 페이지를 기대했는지 또는 코드를 다른 페이지로 옮길 방법을 이해하지 못했습니다. 도움을 얻기 위해 시도한 것을 설명 할 수 있습니까? 당신은 당신의 코드가 다른 페이지로 옮겨 가려고하지 않기 때문에 –

+0

나는 콘텐트를 가진 쿠키를 제공하고 있어도 콘텐트를 얻지 못한다는 것을 의미한다. 그리고 브라우저에서 이것을 시도 할 때 완벽하게 작동하는 것처럼 리다이렉트되고있다. – Rohit