I have developed one simple application in J2ME. Application just does simple HttpConnection
and makes only request. Here is the code for that:
public void run() {
System.out.println("Inside saveData");
HttpConnection hc = null;
OutputStream dout = null;
try {
System.out.println("custName = " + custName);
System.out.println("prodName = " + prodName);
System.out.println("qty = " + qty);
hc = (HttpConnection) Connector.open("http://www.sufalamtech.com/demo/mobile/test.php?custName=" + custName + "&prodName=" + prodName + "&qty=" + qty);
//hc = (HttpConnection) Connector.open("http://www.sufalamtech.com/demo/mobile/test.php?custName=Custtt51&prodName=Proddd52&qty=53");
//hc = (HttpConnection) Connector.open("http://www.sufalamtech.com/demo/mobile/test.php?custName="+custName+"&prodName="+prodName+"&qty="+qty);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.1");
hc.setRequestMethod(HttpConnection.GET);
dout = hc.openOutputStream();
} catch (Exception e) {
System.out.println("Error... = " + e);
} finally {
try {
if (dout != null) {
dout.close();
}
if (hc != null) {
hc.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
This works fine in PC (simulator). But when I am deploying .jar file on my Nokia 5310, it is not returning anything from HttpConnection.
Actually I don't want to receive any data from URL. I just want to send request to my URL. Else will be done by that URL only... My Application works fine in Nokia 3110 Classic. But it is not working on Nokia 5310. Do you have any suggestion?
The problem is that on some implementations, your application might not even send the request until you have invoked the connection.getResponseCode() method. Try invoking the getResponseCode() method before opening the InputStream or OutputStream