I've recently began programming Midlets, and I'm trying to write my first Midlet that uses http connection, but I have stumbled upon something. First of all I used the code given in this article : http://developers.sun.com/mobility/midp/articles/permissions/ (under the section "Making an HTTP Connection". It is a very simple Midlet. The main code is this :
When I use the wireless toolkit to test it with the url "http://wireless.java.sun.com/" or with any other URL on the web (ie. www.google.com) I get good results. In addition I have installed apache tomcat localy on my computer. When I give my browser a localhost address everything works fine. I have put a very simple html page for example that says Hello and when I give my browser the address "http://localhost/Hello.html" it displays it correctly. But when I give the same address to my Midlet, it just says "Error ...". What is wrong here? After adding this line to the Midlet the wireless toolkit prints "404". How come the page displays correctly through Firefox, but the Tomcat returns a 404 to the Midlet? Is my Midlet wrong somehow, or is my wireless toolkit configuration or tomcat not correct?
Thank you very much and in advance for your reply!
Are you sure it's Tomcat returning the 404? 404 is the HTTP standard status code for Page Not Found. You can get it any time an http request cannot be satisfied due to inability to resolve the URL. It includes situations where you're contacting a proxy web server that doesn't know how to pass the request along and if memory serves me correctly, you can also get 404's when DNS isn't working properly or when you haven't got a functional gateway (for example, when you're using WiFi to handle your web requests and the device hasn't connected to a gateway device such as a wireless router).
Customer surveys are for companies who didn't pay proper attention to begin with.
Apparently in my windows machine localhost does not translate to 127.0.0.1 for some reason. I thought it would but it does not apparently. Does someone maybe know why? The hosts file under C:\WINDOWS\system32\drivers\etc directory mentions that 127.0.0.1 is locahost...
I think that when you use localhost you need to insert the port, in my case I use : "http://localhost:8080/app", and works fine.
Joined: Aug 05, 2004
thanks for your reply! The problem was not at appending the port number at the URL, since I configured Tomcat to use port 80 instead of 8080 cause I don't have another web server installed on my machine. The problem is that the DNS that wtk uses does not translate localhost to 127.0.0.1.