• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

requesting a web page through httpclient

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I am trying to get the contents of a protected web page by using httpclient in a java program. After requesting a post method to authenticate on the website, when i make a get request for the protected page, it is giving me html which is when copied and saved to an html file and if opened in browser directly forwards you to required protected page. But how to get that page html in program itself.
As the html content i am getting is directly forwarding me to the protected page when opened in browser, so it seems that the authentication is successful but the problem is to get the real html content of that page in program only.

Regards,
Priyanshu
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does it perform the redirect? Through a refresh header or a JavaScript call? HttpClient has no notion of interpreting the HTML or JavaScript it receives, or of honouring any refresh headers. For actual HTTP "conversations" like this, i.e. a back-and-forth between pages, I prefer to use HttpUnit (on SourceForge). Although, without knowing what's happening on the page, I can't say whether it could handle this situation.
 
priyanshu dubey
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ulf,
it's performing a redirect through javascript.

A part of that html is like:
function checkErrorAndSubmitForm( formName, doPOST, redirUrl){
if( !xdomError ) {
snsSubForm( formName, doPOST, redirUrl);
}
}

Now can u give me a clue how to handle the situation.
Thanks for ur reply,
Priyanshu
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use HttpUnit instead of HttpClient - it can handle JavaScript. You can find an introduction here.
 
priyanshu dubey
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ulf,
I used httpunit. It seems very buggy or say still in development sort of product. JavaScript support is very basic at present. It throws an error when it encounters something in javascript which is not yet supported like 'timeout'. Also there are many more problem with it. I even cudnt make successful authentication with it. I am trying things out, if there is any demo or any suggestion u have for httpunit,do let me know.
Also at the very best, if there is any way to make javascript redirection possible with httpclient, do let me know.
Thanks for your help
Priyanshu
 
    Bookmark Topic Watch Topic
  • New Topic