?
Solved

J2ME HTTP POST not working with static IP address

Posted on 2006-03-30
7
Medium Priority
?
1,411 Views
Last Modified: 2007-11-27

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();
0
Comment
Question by:dgbweb
  • 3
  • 3
7 Comments
 
LVL 9

Assisted Solution

by:OBCT
OBCT earned 1200 total points
ID: 16342536
Have you tried specifying the port number for that IP?
0
 
LVL 3

Author Comment

by:dgbweb
ID: 16342595
yes, I tried appending ":80" to the ip address. Didn't help with either site.

any other ideas?
0
 
LVL 13

Expert Comment

by:bglodde
ID: 16343928
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
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
LVL 13

Expert Comment

by:bglodde
ID: 16343941
Also, does this happen in the emulator, just on the device, or both?
0
 
LVL 3

Author Comment

by:dgbweb
ID: 16345032
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
 
LVL 13

Accepted Solution

by:
bglodde earned 800 total points
ID: 16347303
"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
 
LVL 3

Author Comment

by:dgbweb
ID: 16374269
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MAC Filtering: MAC filtering is like handing a list of names to a doorman. If someone comes to the door and mentions a name, this name is checked by the doorman on his list and granted or denied access by this. This means that if someone menti…
This program is used to assist in finding and resolving common problems with wireless connections.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question