Networking
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   wrangler_gui
Posted On:   Sunday, April 25, 2004 10:22 PM

Urgent I am working on a java application that accepts URL of a website and retrieves pages of that website. It works like this. when user enters URL (eg. http://www.javaworld.com), it first detects the homepage filename of that website by connecting the site with HttpURLConnection,looping through an array containing some common filenames (eg. index.html,default.html etc) and checkimg response code. If response code is 200(OK), I am reading data and storing it in harddisk.The problem is I am able to connect to the site but when I am trying to read the page using Stream classes, it is returning null. If anyone can help me in this. Here is the code : import   More>>

Urgent


I am working on a java application that accepts URL of a website and retrieves pages of that website. It works like this.

when user enters URL (eg. http://www.javaworld.com), it first detects the homepage filename of that website by connecting the site with HttpURLConnection,looping through an array containing some common filenames (eg. index.html,default.html etc) and checkimg response code. If response code is 200(OK), I am reading data and storing it in harddisk.The problem is I am able to connect to the site but when I am trying to read the page using Stream classes, it is returning null.

If anyone can help me in this.

Here is the code :




			

import java.net.*;
import java.io.*;

public class Test
{

public static void main(String args[])
{
try
{
System.getProperties().put("proxySet","true");
System.getProperties().put("proxyHost","proxyhostname");
System.getProperties().put("proxyPort","proxyportno");

String file_name[] = {"/index.htm","/index.html","/default.htm","/default.html","/index.asp","/index.jsp"};

String s = args[0];

for(int q=0;q
{
URL url = new URL(s+file_name[q]);

HttpURLConnection huc = (HttpURLConnection)url.openConnection();

System.out.println("checking response code " + huc.getResponseCode());

if(huc.getResponseCode() == 200)
{
huc.setDoInput(true);
huc.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
String str;
while((str = br.readLine()) != null)
System.out.println(str);
break;
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}

}

   <<Less
About | Sitemap | Contact