Logging into a webpage

Hi,

I need to access a secure webpage using Java.

Normally, to login, I need to enter userID, password and the server that I want to connect to..

The page is made up of PHP.

I tried using Authenticator, but didn't work.

Can anyone tell me how to proceed with this?

--KB

[314 byte] By [neo4ua] at [2007-11-27 4:25:42]
# 1
Is the server using the post or the get method to submi the data?
betlora at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...
# 2
The server is using POST method...
neo4ua at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...
# 3

HI,

Ok, your server is using the post method. Therefore it is interesting for u to have a look at the PrintStream class.

http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html

I suppose you have allready an establised Socked to the Server. In that case it is easy for u to get an Outputstram to set up the PrintStream. As soon as this is done u can submit your datas through the println method form the PrintStream class.

betlora at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...
# 4
I've actually tried all that....It doesn't allow me to access the pages.Is there any other way?
neo4ua at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...
# 5

Lemme give you the code:

( I've made up the server name and IP address here. But, used the real data in my code. )

try

{

Socket s=new Socket("200.200.200.200",80);

BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));

PrintWriter out=new PrintWriter(s.getOutputStream(),true);

str="HEAD /src/redirect.php?login_username="+name+"&secretkey="+password+"&loginServer=MyServer HTTP/1.0\n";

out.println(str);

str="a";

int count=0;

String test;

String cookie[]=new String[3];

for(int i=0;i<13;i++)

{

str=in.readLine(); // == null if error in connection

if(str.length()>8)

{

test=str.substring(0,10);

if(test.equals("Set-Cookie"))//We need cookies: can't proceed unless we have them

{

cookie[count]=str.substring(11)+";";

count++;

}

}

}

String cookies="Cookie:"+cookie[0]+cookie[1]+cookie[2];

in.close();

out.close();

s.close();

str="a";

s=new Socket("202.141.80.21",80);

in=new BufferedReader(new InputStreamReader(s.getInputStream()));

out=new PrintWriter(s.getOutputStream(),true);

str="GET /src/right_main.php HTTP/1.0\n"+cookies+"\n";

out.println(str);

while((str=in.readLine())!=null)

{

System.out.println(str); // write to mail.txt

}

in.close();

out.close();

s.close();

}

catch(IOException e)

{

System.out.println(e);

}

catch(StringIndexOutOfBoundsException z)

{

System.out.println(z);

}

neo4ua at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...
# 6
Hi,You can try it through an URL with an post request: http://www.exampledepot.com/egs/java.net/Post.htmlMessage was edited by: betlor
betlora at 2007-7-12 9:33:56 > top of Java-index,Core,Core APIs...