Wednesday, February 21, 2007

How To Transfer Data Via HttpConnection

You can send data from your mobile phone via Http Connection.In our thesis we will use this method.Our j2me interface is:
javax.microedition.io

Interface HttpConnection

How to open a connection?

private HttpConnection c = null;
private InputStream is = null;
private OutputStream os = null;
private static String ="http://localhost:8084/YourWebApp/YourServlet/

8084:Default TomCat Port in NetBeans IDE

c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = c.openOutputStream();
os.write(msg.getBytes());
os.close();
c.close();

Add try catch for bold area.


No comments: