Hector said:
Hi everybody,
1. Yes, I can access my database because I have another code to view
some information from it. In addition to this, I changed my code. I
only try to read the file now (see code below).
2. Yes, I can access xml file with my browser (IE6 or Mozilla
Firefox).
3. My code is simple, because I changed it for a basic class to test:
package prueba;
import java.net.*;
import java.io.*;
public class prueba {
public prueba() throws Exception
{
URL url=new URL("
http://www ... file.xml");
HttpURLConnection huc=(HttpURLConnection) url.openConnection();
What are you doing here? URL.openConnection returns URLConnection.
Though this may not be causing the problem.
InputStream is = huc.getInputStream();
}
}
And my index.jsp ...
Here few more questions,
1) which is your browser? IE? If browser is IE (internet explorer) it
automatically send logged in domain, user id and password. So you won't see
actual authentication happening.
2) Which is your web server where your XML file is kept?
Below code works perfectly fine for me to fetch any document on the web!
<code>
package test;
import java.io.*;
import java.net.*;
public class HttpTester {
private String path;
public HttpTester(){
this.path="";
}
public HttpTester(String path){
this.path=path;
}
public void setPath(String path){
this.path=path;
}
public String getPath(){
return this.path;
}
public String getContent(){
String content="";
try{
URL url= new URL(this.path);
StringBuffer sb=new StringBuffer();
try{
URLConnection con=url.openConnection();
String s;
boolean shouldRead=true;
InputStream is=con.getInputStream();
BufferedReader br=new BufferedReader(new
InputStreamReader(is));
while(shouldRead){
s=br.readLine();
if(s==null){
shouldRead=false;
}else{
sb.append(s);
sb.append("\n");
}
}
content=sb.toString();
}catch(IOException ioe){
ioe.printStackTrace(System.err);
}
}catch(MalformedURLException me){
}
return content;
}
public static void main(String[] args) {
HttpTester ht=new
HttpTester("
http://www.myserver.com/requiredpage/index.html");
System.out.println(ht.getContent());
}
}
</code>
regards
Holla