Logging in on website using java
Hello,
I am quite inexperienced when it comes to java programming, so my apologies if I post this in the wrong section.
I am trying to open a website using java. So far I succeeded in reading the source code through java, which is about halfway I want to get. However, for getting the information I want, I need to login on the website with my account. I have no idea how something like that should be done. Cookies are used to login, and I am using BlueJ for my program. Could anyone help me out with an example or explanation on how this is done?
Thanks in advance,
Tybs
I downloaded the httpclient tool, it looks promising. I managed to open it in blueJ, so far so good... the only problem now is that I can't compile it. Each class gives me an error message. This one, for example:
import test.com.meterware.httpunit.*;
package test.com.meterware.httpunit does not exist
I found the necessary packages in the tool itself, but I have no idea how I can specify the path to them, or how I can add them to the packages that java already has. What do I need to do for this?
Thanks for the information so far, it really helps :D
Greetz,
Tybs
Similar Messages
-
Accessing seured website using java URL/Socket programming
Hi,
I am working on an intranet search engine using java URL and Authenticator class. This is a secured web-site using SSL in http server. I am not able to access the password protected pages. Following is the code:
URL url = new URL("https://*************");
URLConnection connection = url.openConnection();
PasswordAuthentication pa = Authenticator.requestPasswordAuthentication( InetAddress.getByName(connection.getURL().getHost()),
connection.getURL().getPort(), connection.getURL().getProtocol(), null, "Basic");
StringBuffer buf = new StringBuffer("*****************");
buf.append(":");
buf.append("************");
String encoded = new sun.misc.BASE64Encoder().encode(buf.toString().getBytes());
connection.setRequestProperty ("Authorization", "Basic" + encoded);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
Let me know if there is any other alternative
tnx,
Biswajit BiswalBelow is my first test program. I first take the home page of a website (this can be automated later) and save it to "myTest.html". Then I try to see if this page contains the keywords that a company website often has.
Could you give your opinion on this approach?
If this approach is fine, then any idea about the keywords to select a company website from other sites is welcome.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class MyTest {
* @param args
* @throws IOException
public static void main(String[] args) throws IOException {
InputStream in = MyTest.class.getResourceAsStream("/myTest.html");
Reader reader = new InputStreamReader(in, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
line=line.toLowerCase();
if (line.contains("contact us")) {
System.out.println("contact us: line = "+line);
if (line.contains("career")) {
System.out.println("career: line = "+line);
if (line.contains("company")) {
System.out.println("company: line = "+line);
if (line.contains("about us")) {
System.out.println("about us: line = "+line);
if (line.contains("product")) {
System.out.println("product: line = "+line);
bufferedReader.close();
reader.close();
} -
How can i login to a website using java
hi,
i tried to write a java program to which will take username and password and login to a given site. but some how its not working. i am actually trying to login to the follwoing website:
https://roundup.ffmpeg.org/roundup/ffmpeg/
can anyone provide some example program to login to this website.
br
mahbubul-syeedHi,
i am really sorry... but i am new in this forum and i did not know this. here is my code that i have written. it did not show any error and displays the content of the page but did not logged in. please give your comment.. i badly need a solution.
package myUtility_files;
import java.net.*;
import java.io.*;
public class LogInByHttpPost {
//private static final String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
private static final String LOGIN_ACTION_NAME = "submit";
private static final String LOGIN_USER_NAME_PARAMETER_NAME = "__login_name";
private static final String LOGIN_PASSWORD_PARAMETER_NAME = "__login_password";
private static final String LOGIN_USER_NAME = "mahbubul";
private static final String LOGIN_PASSWORD = "mahbubul007";
private static final String TARGET_URL = "http://roundup.ffmpeg.org/roundup/ffmpeg/";
public static void main (String args[])
LogInByHttpPost httpUrlBasicAuthentication = new LogInByHttpPost();
httpUrlBasicAuthentication.httpPostLogin();
public void httpPostLogin ()
try
// Prepare the content to be written
// throws UnsupportedEncodingException
String urlEncodedContent = preparePostContent(LOGIN_USER_NAME, LOGIN_PASSWORD);
HttpURLConnection urlConnection = doHttpPost(TARGET_URL, urlEncodedContent);
//String response = readResponse(urlConnection);
System.out.println("Successfully made the HTPP POST.");
//System.out.println("Recevied response is: '/n" + response + "'");
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
catch(IOException ioException)
ioException.printStackTrace();
System.out.println("Problems encounterd.");
private String preparePostContent(String loginUserName, String loginPassword) throws UnsupportedEncodingException
// Encode the user name and password to UTF-8 encoding standard
// throws UnsupportedEncodingException
String encodedLoginUserName = URLEncoder.encode(loginUserName, "UTF-8");
String encodedLoginPassword = URLEncoder.encode(loginPassword, "UTF-8");
String content = "login=" + LOGIN_ACTION_NAME +" &" + LOGIN_USER_NAME_PARAMETER_NAME +"="
+ encodedLoginUserName + "&" + LOGIN_PASSWORD_PARAMETER_NAME + "=" + encodedLoginPassword;
return content;
public HttpURLConnection doHttpPost(String targetUrl, String content) throws IOException
HttpURLConnection urlConnection = null;
DataOutputStream dataOutputStream = null;
try
// Open a connection to the target URL
// throws IOException
urlConnection = (HttpURLConnection)(new URL(targetUrl).openConnection());
// Specifying that we intend to use this connection for input
urlConnection.setDoInput(true);
// Specifying that we intend to use this connection for output
urlConnection.setDoOutput(true);
// Specifying the content type of our post
//urlConnection.setRequestProperty("Content-Type", POST_CONTENT_TYPE);
// Specifying the method of HTTP request which is POST
// throws ProtocolException
urlConnection.setRequestMethod("POST");
// Prepare an output stream for writing data to the HTTP connection
// throws IOException
dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
// throws IOException
dataOutputStream.writeBytes(content);
dataOutputStream.flush();
dataOutputStream.close();
return urlConnection;
catch(IOException ioException)
System.out.println("I/O problems while trying to do a HTTP post.");
ioException.printStackTrace();
// Good practice: clean up the connections and streams
// to free up any resources if possible
if (dataOutputStream != null)
try
dataOutputStream.close();
catch(Throwable ignore)
// Cannot do anything about problems while
// trying to clean up. Just ignore
if (urlConnection != null)
urlConnection.disconnect();
// throw the exception so that the caller is aware that
// there was some problems
throw ioException;
br
mahbubul-syeed
Edited by: mahbubul-syeed on Jun 11, 2009 5:07 AM -
My Gmail has a box to tick saying save my details , my golf club has a box saing save my details and my banks have boxes to tick if you want your customer number saved on this computer I tick them but always have to enter them when signing on..this worked previously
Websites remembering you and automatically log you in is stored in a cookie.
* Create an allow cookie exception (Tools > Options > Privacy > Cookies: Exceptions) to keep such a cookie, especially for secure websites and if cookies expire when Firefox is closed.
Make sure that you do not run Firefox in Private Browsing mode.
* https://support.mozilla.com/kb/Private+Browsing
* In [[Private Browsing]] mode all cookies are session cookies that expire if that session is ended, so websites won't remember you.
* Do not use [[Clear Recent History]] to clear the "Cookies" and the "Site Preferences"
Clearing "Site Preferences" clears all exceptions for cookies, images, pop-up windows, software installation, and passwords.
* http://kb.mozillazine.org/Cookies -
RSS feed headlines on website using Java
Good evening,
I am interested in showing the titles of blog posts as
headlines on our website. (The RSS feed would be converted, etc.) I
found free plug-and-play javascript generators that will do this,
but they are giving me validation errors and have not been ideal.
I
found a .jsp file that says it will do the job but it hasn't.
Anybody have experience with this or know something that
works? I'd like to host the script myself if possible. PHP is not
an option for me.
Thank you,
NickFYI: Java is not shorthand for JavaScript. These are two
entirely different programming languages.
To answer your question about fetching feeds with
JavaScripts,
I use this one on my website. It works great.
Google Ajax feedfetcher - requires you to have a Google API
key#
http://www.dynamicdrive.com/dynamicindex18/gajaxrssdisplayer.htm
or this one:
Feed Roll - javascript generator for including news feeds in
websites:
http://www.feedroll.com/rssviewer/
Nancy O.
Alt-Web Design & Publishing
www.alt-web.com/ -
I cannot log into a website using firefox
Hello
I cannot log into a companies website that I work for using firefox. http://www.serviceplussupply.com/Hello spacebyrdz, any luck if you [https://support.mozilla.org/en-US/kb/delete-cookies-remove-info-websites-stored#w_delete-cookies-for-a-single-site delete the cookie for that site] ?
clear the cache also, go from "3-bar" menu button > Preferences > Advanced panel > Network tab > in the Cached Web Content section > click Clear Now.
thank you -
Website use Java but not support Microsoft JVM
This website (www.esdlife.com.hk) only support Microsoft JVM but not Sun JAVA JVM, I can't logon into their service pages until I disable my Sun JVM or unless I use another computer it has Microsoft JVM installed. Those pages even don't let me use other web browser like Netscape except Internet Explorer. I am an amateur Java programmer and I have been studying Java for three years. I don't know if this is an issue to the future of Java Technology. This website supported by the Hong Kong government I believe. Could anyone response my question?
Thanks in advance!
Peter
[email protected]What has probably happened is that the site you are talking about wrote thier page with Microsoft Java, which isn't really Java. They probably used some class, or number of classes, that is specific to the Microsoft VM. This is not a problem with Java, it is a problem with Microsoft makeing their Java uncompatible with Java.
-
Getting the log files from client using java program
hi
this is lalita...and i am doing a project in networking.... i am new to socket programming....i have established the socket connection between the client and server...with this site members' help....now i have to get the log files of the client system from the server.... via the created socket....i need it by tomorrow...i.e apr 12th ....as i have to show it to my guide...
i just need a core java program that will get the log information of the client from the server......
Can anybody please help me in this regard..... it would be of great help to me and my group....
Anxiously awaiting for the replies....
Thanking you and regards...
Lalita.Simple.
Server is listening on a specific port for the connection from the clients.
Connect the client with the server on the above mentioned port.
Open the streams on both side for the connection and run in separate thread.
Define a protocol for communication between client and server.
e.g after connection with the server the server send a text message to the client (send log) now the client first should the log file name and size to the sever and then send the file. the server should save the file.
then disconnect the client or want to get another file or for other tasks define the other commands -
How can I use java on the web?
hi
I would like to learn about making websites using java?? do i have to learn about javascript or another type of java??
Im new in using java applet, threading and stuff like that :).
And maybe I can make management systems in java language is this possible?
thanksmshadows wrote:
hi
I would like to learn about making websites using java?? do i have to learn about javascript or another type of java??
javascript is not a type of java. It is a separate language. What do you mean by "making websites". A website in its simplest form is just an HTML page. If you want to learn what's called a "server side web programming language", which will allow you to do things like retrieve data that a user entered into a form on an HTML page and store it in a database, then first you need to learn basic java, and then you need to learn basic HTML(and it would be beneficial to learn basic javascript although that's not mandatory), and then you need to learn "servlets+jsp"--which is the java version of a "server side web programming language". The easiest "server side web programming language" to learn and the one that is most popular is php.
Some books you might consider:
beginning Java: "Java2: A Beginner's Guide"
beginning servlets+jsp: "Murach's Java servlets and JSP(2008 edition)" -- includes an introduction to HTML
Im new in using java applet, threading and stuff like that :).OK. You don't need know applets or threading to learn servlets+jsp.
And maybe I can make management systems in java language is this possible?
Sure.
Edited by: 7stud on Jun 6, 2008 10:17 PM -
Hey all,
I am making a program which logs into a website and performs some activities on their for me...
I am going to use the Robot class to navigate between pages...
My Question is: Do i actually have to create my own browser to perform my activities or is there another way of doing it?
One more question: If i can log into the website using my program, then when my program attempts to connect to a website which you can
only view once logged in, will it connect?
Not quite sure if these questions are clear enough. Please tell me if you have difficulty understanding.
Thanks:)Thanks for that question I forgot to include that.
All i need is a user agent, something that can log into a website and from there attempt to connect to links in that website and analyse the html
code from there. so i just need to know how to log in and open new websites.
Oh and before anyone thinks im lazy please understand that i have researched other examples already, however they all have extra actions which i do not need
in my program, but im not sure which codes to take out and which to keep...
Once again, thanks all :) -
Connecting to http web site using java socket
Hi,
Sockets in Java I believe are reusable. Once created, it can be used to send a request using its input stream and get back a response using the output stream. My problem is I am trying to connect to a website using java socket but I am unable to get a response (though the same works fine I use URL and URLConnection). Can anyone tell me whats wrong? Below is the client program:
public class HttpAdapterTest {
public static void main(String[] args) {
try {
Socket socket = new Socket("www.google.com", 80);
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream()));
out.write("GET /help/basics.html HTTP/1.1");
out.flush();
BufferedReader in = new BufferedReader(
new InputStreamReader(ucon.getInputStream()));
String line = null;
while((line = in.readLine()) != null) {
System.out.println(line);
in.close();
} catch (Exception e) {
e.printStackTrace();
}Look at the JSSE examples. You need to setup a key store, add the jsse jars to your classpath, yadda, yadda, yadda....
-
New "Windows Programming Using Java" Website
Our newly created "Windows Programming Using Java" website (http://fivedots.coe.psu.ac.th/~ad/winJava/) is for programmers who want to extend Java's capabilities on Windows XP and/or Vista, but aren't sure where to start. One of the drawbacks of Java's portability is that many Java programmers have a rather sketchy knowledge of Windows-specific programming.
We plan to explain how Java applications can utilize Windows application software, OS features, and hardware beyond the reach of Java's standard libraries. A variety of Java/Windows programming techniques will be explained, including:
* Java's employment of the Win32 API via C, JNI, and J/Invoke.
* Java's utilization of Window's Command Line Interface (CLI) and batch files, accessed through Java's Runtime, ProcessBuilder, and Process classes.
* Java and Windows object-based scripting, centered around the use of VBScript, Windows Script Host (WSH), and Windows Management Instrumentation (WMI).
* Java interoperability with COM, including hosting of ActiveX controls in Swing containers using jacoZoom.
This website is a work in progress, with four chapters available for download at the moment. We'll be adding more regularly, and would love feedback on what we're doing.
Thanks,
Gayathri Singh and Andrew Davison
[email protected] and [email protected]
Edited by: AndrewDavison on Jun 20, 2008 1:36 AMHi, I am looking the similar kind of requirement that you had done.. Do you have any more details on the code that is working for you . All i need is if the user logs in successfully in windows, the the app should be accessible. Please let me know if you have the code with you on this problem.
Thanks in advance
"what i meant is the we b applications running in my system, when i access the application iam able to to login automatically with windows authentication and now in case of other users following process happened:" -
Trying to Access Website using SSL running JAVA from inside ORACLE DB
Hi,
I am trying to access website using SSL and running JAVA code from inside Oracle 10g DB server using SSL and Java. I have loaded my java code into Oracle data base. My problem is when I am running same code from outside the DB it is running perfectly fine but when the same code is loaded into DB and trying to run from DB under these environment I am using for running my code:-
JDK 1.4.2_06
JSSE 1.4
Database :- Oracke 10G
I am getting following Exception:-
CALL testssl_http_mar20_New();
java.io.IOException: Unable to tunnel through 123.456.789.123:80. Proxy returns "HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied.)
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a(DashoA12275
at
com.sun.net.ssl.internal.www.protocol.https.HttpsClient.doConnect(DashoA12275)
at
com.sun.net.ssl.internal.www.protocol.https.NetworkClient.openServer(DashoA12275
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.l(DashoA12275)
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.<init>(DashoA1
2275)
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.<init>(DashoA
12275)
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a(DashoA12275
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a(DashoA12275
at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.connect(DashoA122
75)
at
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.getInputStream(Da
shoA12275)
at java.net.URL.openStream(URL.java:924)
at SecureURLhttp_Mar20_New.SecureURLhttp_Mar20_New(
source code is below :-
import java.io.*;
import java.net.*;
import java.security.*;
import java.util.*;
public class SecureURLhttp
public static void main(String[] args) throws Exception
SecureURLhttp r = new SecureURLhttp();
r.SecureURLhttp();
public static void SecureURLhttp() throws IOException
System.setProperty("java.protocol.handler.pkgs","oracle.aurora.rdbms.url|com.sun.net.ssl.internal.www.protocol");
System.setProperty("https.proxySet","true");
Authenticator.setDefault(new MyAuthenticator());
System.setProperty("https.proxyHost","123.456.789.123");
System.setProperty("https.proxyPort","80");
// URL verisign = new URL("https://login.oracle.com/");
URL verisign = new URL("https://www.verisign.com");
BufferedReader in = new BufferedReader(new InputStreamReader(verisign.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
/* Code Newly Add for checking the system property */
java.util.Properties props = System.getProperties();
java.util.Enumeration propNames = props.propertyNames();
while (propNames.hasMoreElements ())
Object o= propNames.nextElement();
String name = (String ) o;
String val = props.getProperty(name) ;
System.out.println ( name + " = " + val );
private static class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("<USERNAME>",new String("<USER_PASSWORD>").toCharArray());
}Please help me out:
Thanks a lot in advance.0- the fact the ISA server logs an 'anonymous' seems logical, since it answers by HTTP 407. I will say it's even a "good log" :) but I had preferred a good old "security exception" but it's not the case..
1- The code for checking the properties (your debugging) should be placed BEFORE trying to connect to the url if you want to see what's happening
2- The 'normal' way to set the proxy is to set the following properties
System.setProperty("http.proxySet","true"); // and NOT https.proxyset as ejp said
System.setProperty("http.proxyHost","123.456.789.123");
System.setProperty("http.proxyPort","80");
3- what's the behavior if you change 123.456.789.123 by the real name (hostname) of the server ?
4- You can try setting up the proxy in the java control panel instead of in your code (easy to do under Windows, you look for the networking settings, and you find the proxy settings for http/https there. Otherwise look for all files called net.properties and edit them).
5- to help debbuging, we can rely on several methods of Authenticator :
protected PasswordAuthentication getPasswordAuthentication() {
System.err.println(".\tgetRequestingHost: " + getRequestingHost());
System.err.println("..\tgetRequestingSite: " + getRequestingSite());
System.err.println("...\tgetRequestingPort: " + getRequestingPort());
System.err.println("....\tgetRequestingProtocol: " + getRequestingProtocol());
System.err.println(".....\tgetRequestingPrompt: " + getRequestingPrompt());
System.err.println("......\tgetRequestingScheme: " + getRequestingScheme());
return new PasswordAuthentication("<USERNAME>",new String("<USER_PASSWORD>").toCharArray());
Try all this and let us see the output messages.
Please remember to give some 'duke stars' if it helped resolving the problem ;)
NephYliM -
''dupe of https://support.mozilla.org/en-US/questions/1027400 - locking''
Whenever I log onto a website via https, I get this message and am unable to have Firefox save my password for the website.
Another user asked this question and it was answered, however, the user was asking in the context of his own website where he was able to change the code.
I am unable to change the code for this website but would like to disable this message and have Firefox remember my password for the user id I type in.
Whenever I log onto a website via https (including my website), I get this message:
Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party. Are you sure you want to continue sending this information? This is followed below with two boxes, "continue" and "cancel".
In order to connect with the website, I must click on "continue" each time I log onto the website. HOW do I permanently DISABLE this message?
Chosen solution
Firefox gives that error because the page is on HTTPS but your form action is HTTP:
<form action="http://eclipse69forum.com/index.php?app=core&module=global§ion=login&do=process" method="post" id="login">
Can you change that to HTTPS?There is a disconnect here: if the form is being submitted securely, then you would not get that message. So although you may be looking at an HTTPS address in the address bar, Firefox is warning you that your username and password are going to an HTTP address and being transmitted in the clear rather than being protected.
That's definitely not the normal way to set up a login page. Do you want to give the URL of the problem login page to get specific comments? Without knowing more, it sounds as though it isn't designed for secure logins and you may be wasting your time accessing their login form using HTTPS.
Anyway, to answer your question, I don't think there is a way to disable that warning. -
How to include Logs/log4j in SOA with out using java embedding activity
Hi,
I have a requirement where I need to log the values of a particular variable and need to store it in a new log file. Is there any way to log the details with out using java embedding activity.
Thanks,You can try this.
http://veejai24.blogspot.co.uk/2008/04/simple-way-to-implement-log4j-in-your.html
Thanks,
Vijay
Maybe you are looking for
-
I'm trying to sync my iPhone 5 with my new macbook pro and im trying to back it up and then start from scratch with no pictures or music on it. but it isnt letting me do so. i have no boxes ticked, andi am doing everything the same way i would normal
-
Ipod not syncrhonizing with Itunes
I have an early generation ipod that will no longer synchronize with Itunes. I downloaded Synchios to get the ipod music onto the computer. Then deleted Synchios software. Now, when I connect the ipod, it says it is synchronizing but newly purchas
-
Can't open or move file - In use by Mac OS X
I have a file (movie) I am trying to move to a new external hard drive. I can't move it cause it says it is used by Mac OS X and cannot be moved or if I try to open it says it can't be opened. The permissions are set correctly on this file and it pla
-
Printing from ActiveX Control in crystal report 10 in IE7 not working
Hi, I am using ActiveX Control for printing in Crystal Report version 10 using Java. When I click on print button, ActiveX control dialog box opens and then click print button, the dialog box shows it's printing and does not stop and there is no prin
-
How can i get firefox to remember my user name and password when useing email?
Everytime i want to log into my email,i have to type in my details.I used Firefox before on a previous pc and i was asked if i would like Firefox to remember these.That is not happening this time.Please can you help?Thanks