Hiii 更新2: ありがとうございました。 私は今、クッキーを手に入れましたが、私は同じページにこだわっています。 リクエストでヘッダーとしてcookieを追加しましたが、私は応答と同じページを持っています。 私は間違っていることを知らない。 私を案内してください。次のページに移動できませんhttp://indianvisa-bangladesh.nic.in/visa/Get_Application 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();
}
任意の助けが理解されるであろう!!!! – Rohit