J2ME HTTP Post Method Problem

T

Tony

Hello,
I built a midlet that sends an information by POST method in HTTP
connection.
in the emulators (such as Nokia 6270,6230, 6230i..) I See the "post
data" in the diagnostic, but the data doesn't arrive to the server. I
tried several servers and they didn't work. I tried to run the SDK's on
different computers and it was the same.
If I run my midlet on my Cellphone (6230) everything works fine.
Example for the post data:
action=Login&Username=tony&password=1234

is a known problem?
Any suggestions on how to solve it ?

Here is additional information:

My J2ME Code:
String params = new String("action=Login&username=&password=");
httpConn = (HttpConnection)Connector.open(url, Connector.READ_WRITE );
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "text/plain");
os = httpConn.openOutputStream();
byte postmsg[] = params.getBytes();
for(int i=0;i<postmsg.length;i++) {
os.write(postmsg);
}
os.flush();
StringBuffer sb = new StringBuffer();
is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1) {
sb.append((char) chr);
}
response = new String(sb.toString().getBytes(),"UTF-8");


Here is Simple PHP file which is on the server:

<?php

header('Content-type: text/plain');

if ($_POST["action"]=="Login") {
if($_POST["username"]=='tony') {
echo "<?xml version=\"1.0\"?>\n";
echo "<dictionary>\n";
echo "<Status>1</Status>\n";
echo "<Reason>0</Reason>\n";
echo "<Key>JFKDL54GFDYU85T43NJKGH89N543KGFD</Key>\n";
echo "</dictionary>\n";
exit;
}
else {
echo "<?xml version=\"1.0\"?>\n";
echo "<dictionary>\n";
echo "<Status>0</Status>\n";
echo "<Reason>Wrong Username</Reason>\n";
echo "</dictionary>\n";
exit;
}
}
echo "Not Good!";
?>


When I run the midlet on my cellphone, the server recognize the value
of $_POST["action"]
but when I run the midlet on the emulators, the server doesn't
recognize the value of $_POST["action"]. in other words, the server
doesn't get the string.
But, when I look in the Diagnostic of the emulator I see that the data
were sent.

Here is the log of the Request operation:

Location = [http://10.0.0.101/dic.php]
Request Method = [POST]
Post Data = [action=Login&username=&password=]
Headers (8)
Host = [10.0.0.101]
Content-Type = [ text/plain]
User-Agent = [ Nokia6270/2.0 (p03.20) Profile/MIDP-2.0
Configuration/CLDC-1.1 Profile/MIDP-1.0 Confirguration/CLDC-1.0,
Nokia6270/2.0 (p03.20) Profile/MIDP-2.0 Configuration/CLDC-1.1
UNTRUSTED/1.0]
Content-Length = [ 32]
Connection = [ Keep-Alive]
x-wap-profile = [
"http://nds1.nds.nokia.com/uaprof/N6270r100.xml"]


Here is the log og the response:

Request Status = 200: "OK"
Location = [http://10.0.0.101/dic.php]
Headers (6)
Transfer-Encoding = [ chunked]
Date = [ Tue, 13 Jun 2006 23:30:08 GMT]
Content-Type = [ text/plain]
Server = [ Apache/1.3.33 (Unix) PHP/4.3.10]
X-Powered-By = [ PHP/4.3.10]
Via = [ 1.1 Bezeq-L2TP-MED-Stack1 (NetCache NetApp/5.6.2R1)]
Content Data: 9 bytes, text/plain; ISO-8859-1
Not Good!


(The Not good is the string that appears in the end of the php. we get
there only if the "IF" statment is false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top