Pls. try an URLconnection, it is easier to manage and get working.
Regards - George
Sujoy wrote:
> Hi All ,
>
> I am facing problem while accessing a secured site through my servlet.
> I am acting as browser client .
>
> The code is :
> =====================================================================
> import java.io.* ;
> import java.util.*;
>
> import com.sun.net.ssl.*;
> import javax.net.*;
> import javax.net.ssl.*;
>
> import java.security.*;
>
> public class AuthBasic {
>
> private static final String UIDPWD = "XYZ123:ABC123" ;
> private static final String HOST = "investment.datek.com" ;
> private static final int PORT = 443 ;
>
> public static void main(String args[]){
>
> try {
>
> Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> SSLSocketFactory factory =
> (SSLSocketFactory)SSLSocketFactory.getDefault();
>
> SSLSocket socket = (SSLSocket) factory.createSocket(HOST, PORT);
>
> String strBase64 = new sun.misc.BASE64Encoder().encode
> (UIDPWD.getBytes());
>
> System.out.println("Encoded stuff is :"+strBase64);
>
> // req. string
> String reqStr = "CONNECT / HTTP/1.0\r\n"+
> "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;
> DigExt)\r\n"+
> "Host: investment.datek.com\r\n"+
> "Content-Length: 0\r\n"+
> "Authorization: Basic "+strBase64+"\r\n\r\n";
>
> System.out.println(reqStr);
>
> Writer out = new OutputStreamWriter(socket.getOutputStream());
> // writing to the socket
> out.write(reqStr);
> out.flush();
>
> // read response
> BufferedReader in = new BufferedReader(
> new InputStreamReader(socket.getInputStream()));
>
> String Line ;
> while( (Line = in.readLine()) != null ){
> System.out.println(Line);
> }// eo while
>
> out.close();
> in.close();
> socket.close();
>
> }catch(Exception sickcode){
> System.out.println("The fucking exception is : "+sickcode);
> }
>
> }
>
> }
>
> =====================================================================
> // end of code
> And after that I am not getting the desired page.
> But when I access my account through IE/Netscape I get the correct page.()
> Can anyone plz tell me where I am making mistake/s ?
>
> Thanks and Regards,
> Sujoy
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html