• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Cell Phone Authentication with HTTP protocol

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to create a cell phone interface for a smart sensor network but it requires authentication to a servlet online and submits queries to a remote server that manages the sensors (both the authentication and queries are to the same URL) For some reason my code doesnt want to contact that URL and I can't seem to figure out why. I've been using CORE J2ME by John Muchow and used primarily the code from chapter 14 (pg 534). The program uses POST to submit username and password strings. The servlet should return true if valid. Then the midlet submits the username and the type of data it wants (amount of light in room, temperature etc) which the selvet returns in string (The temperature is ___) I didn't write the servlet and having a problem interpreting some of the statements, but I understand the bulk of it. I did write the midlet though and it does compile. Here are the functions that dont want to work (the prog crashes when it comes to them)
Here are the functions that are giving me trouble.
private void login() throws IOException
{
HttpConnection http = null;
OutputStream oStrm = null;
InputStream iStrm = null;
boolean ret=false;

String url = "192.168.100.101:8080";
System.err.println("Login parameters set");
try
{
System.err.println("Login");
http = (HttpConnection) Connector.open(url);
oStrm = http.openOutputStream();

http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte data[] = ("account=" + tfAccount.getString()).getBytes();
oStrm.write(data);
data = ("&password=" + tfPassword.getString()).getBytes();
oStrm.write(data);

oStrm.flush();
iStrm = http.openInputStream();
ret = processlogin(http, iStrm);
if(ret)
display.setCurrent(lsMain);

else
display.setCurrent(lsRetry);
}
finally
{
// Clean up
if (iStrm != null)
iStrm.close();
if (oStrm != null)
oStrm.close();
if (http != null)
http.close();
}

}
private boolean processlogin(HttpConnection http, InputStream iStrm) throws IOException
{
if (http.getResponseCode() == HttpConnection.HTTP_OK)
{
return true;
}
return false;
}

I'm just wondering if there is any special library or statement I'm missing. I've even tried running all of this locally on the server to no avail. Could somebody let me know if there are some common errors regarding accessing HTTP i might be missing? Thank you in advance I really appreciate it.
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were to do this, I would use "GET" instead of "POST" and append the "?account=XXX&password=XXX" string directly at the end of the request URL.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic