Hello, I am trying to write a small Java client that will talk to a URL and get data: public class HttpRestClient { public static void main(String[] args) { try { //Authenticate Authenticator.setDefault(new Authenticator(){ protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication("admin","password".toCharArray()); } }); // Construct a URL URL url = new URL("http://localhost:8080/"); // Open a connection HttpURLConnection googleConnect = (HttpURLConnection) url .openConnection(); //googleConnect.setRequestProperty("Accept","[star]/[star]"); googleConnect.setDoInput(true); googleConnect.setDoOutput(true); googleConnect.connect(); System.out.println("Response code after connection... "+googleConnect.getResponseCode()); System.out.println("Error Stream.....`\n"+googleConnect.getErrorStream()); // googleConnect.setRequestProperty("From",url.getUserInfo()); // googleConnect.setRequestProperty("Accept-Charset", "iso-8859-5, unicode-1-1"); // googleConnect.setRequestProperty("Accept-Language", "en"); // googleConnect.setRequestProperty("Accept-Encoding", "*"); // googleConnect.setRequestProperty("Cache-Control", "no-cache"); // googleConnect.setRequestProperty("Connection", "keep-alive"); // googleConnect.setRequestProperty("Transfer-Encoding", "chunked"); // Read data from it //InputStreamReader isr = new InputStreamReader(googleConnect.getInputStream()); BufferedReader outputReader = new BufferedReader(new InputStreamReader(googleConnect.getInputStream())); Map<String, List<String>> requestMapping = googleConnect .getRequestProperties(); System.out.println("**************** RESPONSE ***************** \n" + "HTTP 1.1 - Status " + googleConnect.getRequestMethod()+" "+googleConnect.getResponseMessage() + "\n" + "Response Code: " + googleConnect.getResponseCode() + "\n" + "Encoding: " + googleConnect.getContentEncoding() + "\n" + "Content-Type: " + googleConnect.getContentType() + "\n" + "Content-Length: " + googleConnect.getContentLength() + "\n" + requestMapping.values() + "\n\n"); while (outputReader.readLine() != null) { System.out.println(outputReader.readLine()); } outputReader.close(); //googleConnect.disconnect(); } catch (MalformedURLException mfue) { System.err.println("Exception Occurred is:"); mfue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } but it is returning 404 all the time whereas my tomcat is running and I can see all the pages if I access from the web....Does anyone know what the problem is?
Dude.....! Could you please elaborate your answer please....your answer to my thread is very vague and unclear.....and if possible, could you please give me an example....tomcat is a horrible beast to fix sometimes... Thanks