Sorry for posting this question on the JSP list , this is not a very JSP
specific issue , but I am running out of resources , thought someone on this
list may have an answer. Appreciate your responses.
I am trying to retrieve a file from a https connection, while doing so I get an
access denied error. I have verified the userid and password , they are correct
because I am able to post a file on to the same location with the same user id
and password. The file extension is .log and my content-type has a value of
text/html , but I have'nt had success in changing the Content-type.
This is my code
URL url = new URL("https://file location");
URLConnection urlC = url.openConnection();
HttpsURLConnection theConnection = (HttpsURLConnection)urlC;
// Print info about resource
for (int i = 0; i < 10; i++)
{
String headerKey = theConnection.getHeaderFieldKey(i);
System.out.print("HeaderKey " + i + ": " + headerKey);
System.out.println(" Value: " + theConnection.getHeaderField(i));
}
// Copy resource to local file, use remote file
InputStream is = urlC.getInputStream();
// Get File Name
StringTokenizer st = new StringTokenizer(url.getFile(), "/");
String fileName = null;
while (st.hasMoreTokens())
{
fileName = st.nextToken();
}
FileOutputStream fos = new FileOutputStream(fileName);
int oneChar, count=0;
while ((oneChar=is.read()) != -1)
{
fos.write(oneChar);
count++;
}
is.close();
fos.close();
This is the output
Opening connection:
[https://benetest.selfservicenow.com/servicecenter/upload/SS00_2000_09_07_01.log]
Connection opened:
com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection:https://benetest.selfservicenow.com/servicecente
Connection Type: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection
HeaderKey 0: null Value: HTTP/1.1 401 Access Denied
HeaderKey 1: WWW-Authenticate Value: NTLM
HeaderKey 2: Connection Value: close
HeaderKey 3: Content-Length Value: 644
HeaderKey 4: Content-Type Value: text/html
HeaderKey 5: null Value: null
HeaderKey 6: null Value: null
HeaderKey 7: null Value: null
HeaderKey 8: null Value: null
HeaderKey 9: null Value: null
Expected size is: 644
Resource type: text/html
Last modified on: Wed Dec 31 19:00:00 EST 1969...
Permission is: (java.net.SocketPermission benetest.selfservicenow.com:80
connect,resolve)
OPENING STREAM
java.io.FileNotFoundException:
https://benetest.selfservicenow.com/servicecenter/upload/SS00_2000_09_07_01.log
The file does exist , because I can see it when I view it through the browser
Thanks in advance
Santosh
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets