Scott,

I just had the same problem last week.  Below is a copy of the code that
worked for me, without needing to create any HTTP headers or do any Base64
encoding!  You'll need to update the URL and the passwd to your own.

-Nash

---------------------
import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.security.Permission;

public class GetAuthURL extends HttpServlet  {

   public void init(ServletConfig config) throws ServletException  {
        super.init(config);
   }

        public void service(HttpServletRequest req, HttpServletResponse res)
                                throws ServletException, IOException {

                ServletOutputStream out = res.getOutputStream();
                HttpSession sesssion = req.getSession(false);
                URL url = new URL("http://www.yahoo.com"); ///put your ACL protected 
URL
here
                URLConnection connection = url.openConnection();
                Authenticator.setDefault(new MyAuth());
                String contentType = connection.getContentType();
                res.setContentType(contentType);
                        InputStream in = connection.getInputStream();

                char ch;
                        int data = in.read();
                        while (data != -1)  {
                        out.write(data);
                        data = in.read();
                }
                out.close();

        }

        public class MyAuth extends Authenticator  {

                protected PasswordAuthentication getPasswordAuthentication()  {
                        String login = "bnash";
                        char[] passwd = {'b','o','g','u','s','9','9','9'};
                        return new PasswordAuthentication(login, passwd);
                }
        }

}

------------------------



[EMAIL PROTECTED] writes:
>We're trying to get an HttpURLConnection to retrieve a document on a web
>server that is ACL-protected by the listener. Is there a way to pass
>authentication information with the request?

___________________________________________________________________________
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

Reply via email to