Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Bogus 404 for a HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bogus 404 for a HttpURLConnection" Watch "Bogus 404 for a HttpURLConnection" New topic
Author

Bogus 404 for a HttpURLConnection

Rebecca Case
Greenhorn

Joined: Apr 10, 2010
Posts: 5
For some reason when I try and hit even a simple webapp running on my local machine using HttpURLConnection, I keep getting a 404 reponse code. What's throwing me for a loop is that I can hit other URL's such as google and I was able to hit a local grails app that's running on Jetty. But, if I try to hit even a simple html file running from a war that's running on Tomcat 6, I get the 404. And this is a URL that I am able to hit through a browser.

Here is my code:
url = new URL("http://localhost:8080/simpleweb/index.html/");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
System.out.println(connection.getResponseCode());

Does anyone have any ideas on something else to check?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Can you open that URL in your web browser? If not then the problem must be found in Jetty, not in the URLConnection.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rebecca Case
Greenhorn

Joined: Apr 10, 2010
Posts: 5
Yeah, that's what's maddening about this. I can hit the URL in a browser. Plus, I can hit other URL's like "http://www.google.com" using HttpURLConnection just fine. It's just when I try to use it to hit my URL on localhost that's running off of Tomcat...the exact same URL that worked in the browser.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Rebecca Case wrote:the exact same URL that worked in the browser.


Even with that trailing "/", which clearly doesn't belong there?


[Jess in Action][AskingGoodQuestions]
Rebecca Case
Greenhorn

Joined: Apr 10, 2010
Posts: 5
Ernest Friedman-Hill wrote:
Rebecca Case wrote:the exact same URL that worked in the browser.


Even with that trailing "/", which clearly doesn't belong there?


It gets the 404 with or without the trailing "/"
Jordan Larson
Greenhorn

Joined: Aug 23, 2013
Posts: 1

I had this same problem and the problem was another process was stealing my request. I was able to find the solution from this stackoverflow post: http://stackoverflow.com/questions/17433906/404-when-accessing-tomcat-with-httpurlconnection-200-from-browser
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bogus 404 for a HttpURLConnection