Reputation: 3147
Is it possible to handle the pop ups using apache http client?
I am trying to access the website. Accessing a particular page pop's up a new window and in http response all i get the pop up new window code in HTML.
Is there a way to redirect to new pop up window from http client?
My code
HttpResponse res = null;
HttpEntity entity = null;
DefaultHttpClient defClient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://sudhaezine.com/[email protected]&password=yyy&brw=safari");
res = defClient.execute(httpost);
entity = res.getEntity();
StringBuffer sb = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
String str;
while ((str = reader.readLine()) != null) {
sb.append(new String(str.getBytes(), "UTF-8"));
}
entity.consumeContent();
This gives following response
<html><head> <title></title></head><META HTTP-EQUIV=refresh content=30;url=thankyou.php><body background="images/bg1.gif"><script language="javascript">var popupstr=''; //var bor = navigator.appName; //alert(bor); doPopUpWindow = window.open("svww_index1.php","StarView",'width=800,height=600,left=0,top=0'+popupstr); // if (!doPopUpWindow) { //Popup blocked open with in current browser window. // doPopUpWindow = window.open("svww_index1.php","_parent",'width='+ screen.availWidth +',height='+ screen.availHeight +',left=0,top=0'+popupstr); // } try{ var obj = doPopUpWindow.name; // window.close();//WindowOpen.close();//alert("Popup blocker NOT detected"); } catch(e){ doPopUpWindow = window.open("svww_index1.php","_parent",'width='+ screen.availWidth +',height='+ screen.availHeight +',left=0,top=0'+popupstr); }</script></body></html>
Upvotes: 0
Views: 1010
Reputation: 2301
You can't automatically handle such pop-ups with http client because they are created via client JavaScript code. So you need client with JS interpreter (like web browser).
You can proceed by reverse-engineering JavaScript code, passing parameters you grab from response body to resulting function and making new request with http client to generated url. This process is called Web scraping.
Upvotes: 1