• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bogus 404 for a HttpURLConnection

 
Rebecca Case
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you open that URL in your web browser? If not then the problem must be found in Jetty, not in the URLConnection.
 
Rebecca Case
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rebecca Case wrote:the exact same URL that worked in the browser.


Even with that trailing "/", which clearly doesn't belong there?
 
Rebecca Case
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
Chrome Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic