J2ME HTTP POST not working with static IP address


Anyone know why a website would return a 404 error when you specify the IP address rather than the domain name. Both a JSP and a ASP website give me the same response.

The code snippet is below.

// these params work fine
String url = "http://localhost:8080/WebModule2/jsp1.jsp";
String formData = "username=foobar&password=foobar&Submit=Submit";

// these params work fine also
String url = "http://mydomainname.com/LoginProc.jsp";
String formData = "username=foobar&password=foobar&Submit=Submit";

//these params generate a 404 Not Found response from the server
// where the IP used is that reported when you ping the domain name
String url = "http://123.123.123.123/LoginProc.jsp";
String formData = "username=foobar&password=foobar&Submit=Submit";

The code is as follows:

HttpConnection c = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String clen = Integer.toString(formData.length());
c.setRequestProperty("Content-length", clen);                              
OutputStream os = c.openOutputStream();
os.write(formData.getBytes());
os.flush();
os.close();
LVL 3
dgbwebAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OBCTCommented:
Have you tried specifying the port number for that IP?
0
dgbwebAuthor Commented:
yes, I tried appending ":80" to the ip address. Didn't help with either site.

any other ideas?
0
bgloddeCommented:
This is an interesting issue. From a MIDP perspective, there is nothing that should prevent the use of an IP address rather than a hostname.
Does the website respond when you bring it up via IP address in a browser?
0
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

bgloddeCommented:
Also, does this happen in the emulator, just on the device, or both?
0
dgbwebAuthor Commented:
I am just on the emulator at present (sun's wireless toolkit with JBuilder2006). I suppose it is worth a try to download it to the phone and see if it works there or not.

the target page is known to work fine ( a production app is calling it). The browser works fine too.

the same code using the GET method returns an application specific error but at least it indicates the server found the page.

I am getting an html formatted response from the server with the 404 error code and the message that the server cannot find the specified file "/LoginProc.jsp".

If it isn't much work, maybe one of you could cut/paste the code into one of your apps and see what happens in your emulators.

Darren
0
bgloddeCommented:
"the same code using the GET method returns an application specific error but at least it indicates the server found the page"

That's a good clue -

Get the response code from the request and maybe that will lead to a better clue:

// after this line
os.close();

// get the response code
int code = c.getResponseCode();
System.out.println("RESPONSE CODE: " + Integer.toString(code));


Maybe it's throwing back 411 (invalid content-length) or something like that -- at least, we can hope it's a better clue...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgbwebAuthor Commented:
Hi,

the problem turned out to be a combination of needing to append ":80" to a fixed IP address, and setting the content length request property.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Wireless Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.