Original Post
I'm trying to make an application for my mobile phone that exchanges some information with a webpage using HttpConnection.POST. The code works on the simulator (J2ME Wireless Toolkit) but when i try it on my phone it don't work. Any ideas why? import java.io.*; import java.util.Vector; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class Moorgan extends MIDlet implements CommandListener, Runnable { private Display mDisplay; private Form mLoginForm; private Command mExitCommand, mLoginCommand; private StringItem mError; private Thread t; private String url = ""; private String session, message; public void startApp() { mDisplay = Display.getDisplay(this); if (mLoginForm == null) { mError = new StringItem("", ""); mExitCommand = new Command("Exit", Command.EXIT, 0); mLoginCommand = new Command("OK", Command.SCREEN, 0); mLoginForm = new Form("Project Moorgan"); mLoginForm.append("Welcome to Project Moorgan"); mLoginForm.append(mError); mLoginForm.addCommand(mExitCommand); mLoginForm.addCommand(mLoginCommand); mLoginForm.setCommandListener(this); mDisplay.setCurrent(mLoginForm); } } public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c == mExitCommand) { destroyApp(false); notifyDestroyed(); } else if (c == mLoginCommand) { t = new Thread(this); t.start(); } } public void run() { HttpConnection hc = null; InputStream in = null; OutputStream out = null; int temp; try { url = "http://www.carandria.com/test/j2me/test.php"; hc = (HttpConnection)Connector.open(url, Connector.READ_WRITE); hc.setRequestMethod(HttpConnection.POST); hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); hc.setRequestProperty("Content-Language", "en-US"); hc.setRequestProperty("Accept-Language", "en"); message = "name"; hc.setRequestProperty("Content-Length", Integer.toString(message.length())); out = hc.openOutputStream(); out.write(message.getBytes()); in = hc.openInputStream(); int length = (int)hc.getLength(); byte[] data = new byte[length]; in.read(data); String response = new String(data); mError.setText(response); } catch (IOException ioe) { mError.setText("Unable to connect"); mDisplay.setCurrent(mLoginForm); } finally { try { if (out != null) out.close(); if (in != null) in.close(); if (hc != null) hc.close(); } catch (IOException ioe) {} } return; } }