• 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Access web url through java code.  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one problem. I have one web url htpp://127.0.0.1:8080/UserLogin.jsp
Now I have to acees this url though java code not from the web browser.
When I am accessing this page through HttpURLConnection class,
It is ok, but can any body tell me how I can give user name and password through code for this page UserLogin.jsp.

 
Bartender
Posts: 9551
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using form-based authentication? Send the user name and password as request parameters like this example.
If you are using HTTP based authentication, use the Authenticator class as described here.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If login from a browser does POST on a form, you can simulate that nicely with your URLConnection. Set DoInput and DoOutput true, get the output stream from the connection and write your form content. Don't forget to flush and close the stream.

Here's what I write to log on my Wiki ... the form has two hidden fields and the userid & password entry fields:

See the JavaDoc and the Sun Network Tutorial for more details.
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this entry of the Applet FAQ, which describes how to do it. In this regard, applets and applications are identical.
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to write that code for testing purpose HttpUnit can help.

Please read section Testing pool entry in the link below to know if the link helpshttp://httpunit.sourceforge.net/doc/tutorial/task1editor-entry.html
[ September 19, 2006: Message edited by: karthi keyan ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have idea where the form of login.jsp is hitting then you can fake out the login process and there is no harm in this as you are making a tool not the browser.If you know where the login form sumbits like /cool/verify
and username variable is user and password is pass then you can create the url like /cool/verify?user=<userName>&pass=<password> with the url try creating the HTTPURLConnection , similar is the process .The only thing is that user=<userName>&pass=<password> will be in the body and you have to set the header set-content-length header.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!