Re: Http Connection
- From: "Holla" <rbin.kor901209@xxxxxxxxxxxx>
- Date: Mon, 11 Apr 2005 15:02:11 +0530
"Hector" <HEPETI@xxxxxxxx> wrote in message
news:33da8795.0504051432.265fed8@xxxxxxxxxxxxxxxxxxxxx
> > Few questions.
> > 1. Can access xml file in web browser?
> > 2. Can you share code how you are reading URL....
>
> 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
.
- References:
- Http Connection
- From: Hector
- Re: Http Connection
- From: Matt Humphrey
- Re: Http Connection
- From: Hector
- Re: Http Connection
- From: Holla
- Re: Http Connection
- From: Hector
- Http Connection
- Prev by Date: JFreeChart : how to draw some shapes in a chart?
- Next by Date: NIO on sun doesnot give WRITE notification
- Previous by thread: Re: Http Connection
- Next by thread: Url in Jar
- Index(es):
Relevant Pages
|