السلام عليكم ورحمة الله وبركاته ..
احتاج إلى طريقة للدخول إلى مواقع تتطلب اسم مستخدم وكلمة مرور باستخدام الـ j2me ..
للتوضيح أكثر ..
لنفرض أن البرنامج يعرض عدد الإيميلات الغير مقروءة في بريد الهوتميل الخاص بمستخدم ما ..
قرأت أنه يمكنني استخدام فنكشن setPropertyReqest ، ولكن لم أنجح في هذا حتى الآن ):
هلا تفضلتم بإرشادي إلى الطريقة الصحيحة لاستخدامها ، أو طريقة بديلة إن وجدت ؟..
هنا محاولتي الغير ناجحة ..
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import java.lang.*;
import java.util.*;
public class Email extends MIDlet
implements CommandListener {
//The exit commands
private Command exitCommand;
//The display for this MIDlet
private Display display;
Form displayForm;
public Email() {
display = Display.getDisplay(this);
exitCommand =
new Command("Exit", Command.SCREEN, 1);
}
// Start the MIDlet by creating the Form and
// associating the exit command and listener.
public void startApp() {
displayForm = new Form("");
displayForm.addCommand(exitCommand);
displayForm.setCommandListener(this);
try
{
String result = getViaHttpConnection
("http://live.com/login");
displayForm.append(" " + result);
}
catch (Exception exc)
{
exc.printStackTrace();
}
display.setCurrent(displayForm);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(
Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
String parse(String str)
{
}
String getViaHttpConnection(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
StringBuffer str = new StringBuffer();
try {
c = (HttpConnection)Connector.open(url);
String UserName = "";
String PassWord ="";
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "2 Oct 2002 15:10:15 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("-Language", "en-CA");
c.setRequestProperty("-Length",""+ (UserName.length()+PassWord.length()));
c.setRequestProperty("UserName",UserName);
c.setRequestProperty("PassWord",PassWord);
// Get the Type
String type = c.getType();
// Getting the InputStream will open the connection
// and read the HTTP headers. They are stored until
// requested.
is = c.openInputStream();
// Get the length and process the data
int len = (int)c.getLength();
int ch;
while ((ch = is.read()) != -1) {
str.append((char)ch);
}
} finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
// Before returning, the resultant String should be parsed to get Exchange Rate
//String val = parse(str.toString());
System.out.println(str.toString());
return str.toString();
}
}