HTTP operation error on midlet
hi all fellows!
i've got a problem in MIDlet and servlet connection.
i've created a midlet and installed its jad in mobile phone, on PC i run the servlet and midlet, it works properly, but when i run application on the mobile phone, it says "error in HTTP operation".
can anybody help me? i m using this first time.
[342 byte] By [
Muhammada] at [2007-11-27 9:34:30]

# 2
her is my code.
this is on MIDlet side
StringBuffer sb = new StringBuffer();
try {
HttpConnection c = (HttpConnection) Connector.open(url);
c.setRequestProperty(
"User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language","en-US");
DataOutputStream os =
(DataOutputStream)c.openDataOutputStream();
os.writeUTF(selection.trim());
os.writeUTF(user.trim());
os.writeUTF(pwd.trim());
os.writeUTF(Store.trim());
os.flush();
os.close();
// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
int ch;
sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char)ch);
}
if(sb.length()==0)
showAlert("Login not Successful. Try Again or Subscribe if You are not Authorised");
else
{
showAlert(sb.toString());
storeshow=true;
}
is.close();
c.close();
} catch (Exception e) {
showAlert(e.getMessage());
}
}
/* This method takes input from user like db,user and password and pass to servlet */
public void connectDb(String user,String pwd) {
this.user = user;
this.pwd = pwd;
}
and this is on servlet side
Connection conn = null;
ResultSet rs=null;
Statement stmt;
DataInputStream in = new DataInputStream(
(InputStream)request.getInputStream());
try
{
conn = DriverManager.getConnection(
"jdbc:derby://localhost:1527/RetailDB",
"bilal",
"bilal");
String user = in.readUTF();
String pwd = in.readUTF();
stmt= conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM RetailUser WHERE UserName='"+user+"' AND Password='"+pwd+"'");
while(rs.next())
{
out.println(rs.getString("UserName") + " || " + rs.getString("Phone") );
}
}
catch(SQLException e)
{
out.println("SQLException: " + e.getMessage() + "
");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "
");
}
finally
{
//Clean up resources, close the connection.
if(conn != null)
{
try
{
conn.close();
}
catch (Exception ignored) {}
}
}
in.close();
out.close();
wud this be because of setting request property in MIDlet? i tried this on Nokia 6280, but shows "Error in HTTP operation".
# 3
here is my code.
this is on MIDlet side
StringBuffer sb = new StringBuffer();
try {
HttpConnection c = (HttpConnection) Connector.open(url); c.setRequestProperty( "User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language","en-US"); DataOutputStream os = (DataOutputStream)c.openDataOutputStream();
os.writeUTF(user.trim());
os.writeUTF(pwd.trim());
os.writeUTF(Store.trim());
os.flush();
os.close();
// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
int ch;
sb = new StringBuffer();
while ((ch = is.read()) != -1)
{ sb.append((char)ch); }
if(sb.length()==0) showAlert("Login not Successful. Try Again or Subscribe if You are not Authorised");
else
{ showAlert(sb.toString()); storeshow=true; }
is.close();
c.close();
}
catch (Exception e)
{
showAlert(e.getMessage());
}
}
/* This method takes input from user like db,user and password and pass to servlet */
public void connectDb(String user,String pwd)
{
this.user = user;
this.pwd = pwd;
}
and this is on servlet side
Connection conn = null;
ResultSet rs=null;
Statement stmt;
DataInputStream in = new DataInputStream( (InputStream)request.getInputStream());
try
{
conn = DriverManager.getConnection( "jdbc:derby://localhost:1527/RetailDB", "bilal", "bilal");
String user = in.readUTF();
String pwd = in.readUTF();
stmt= conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM RetailUser WHERE UserName='"+user+"' AND Password='"+pwd+"'");
while(rs.next())
{
out.println(rs.getString("UserName") + " || " + rs.getString("Phone") );
}
}
catch(SQLException e)
{
out.println("SQLException: " + e.getMessage() + "");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "");
}
finally
{
//Clean up resources, close the connection.
if(conn != null)
{
try { conn.close();
}
catch (Exception ignored)
{}
}
}
in.close();
out.close();
wud this be because of setting request property in MIDlet? i tried this on Nokia 6280, but shows "Error in HTTP operation".