Hellow everyone,

I have this Java Method below. I used a link which requires authentication and when I ran this in Eclipse, it worked well.

validURL("http://localhost/context/myfile.pdf");

However, when I deployed this in Weblogic, the method returns an error which was " 401Unauthorized".

I tried this link but did not work:

validURL("http://username:password@localhost/context/myfile.pdf");

Can you please give me some suggestions regarding this?

Thanks in advance

private static boolean validURL(String docpath)
    {
        boolean fileExists = false;
        try
        {
            URL u1 = new URL(docpath);
            java.io.InputStream testStream = u1.openConnection().getInputStream();
            fileExists = true;
        }
        catch(IOException e)
        {
        	e.printStackTrace();
        }
        return fileExists;
    }

Can you look at what the server receives when you try to access it with that URL?
What happens if you use that URL in a browser?

I don't know if the URL class has the logic to do the steps needed to respond to a 401 response by generating the Authorization: field in the HTTP response header.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.