FileDocCategorySizeDatePackage
HTTPInfo.javaAPI DocExample1750Thu Feb 16 11:52:12 GMT 2006None

HTTPInfo

public class HTTPInfo extends MIDlet implements CommandListener

Fields Summary
private Display
display
private TextBox
textBox
Constructors Summary
Methods Summary
public voidcommandAction(Command command, Displayable displayable)

    Thread t = new Thread(
       new Runnable() {
         public void run() {
           display.setCurrent(getInfo(textBox.getString()));
         }
       }
     );
     t.start();
  
protected voiddestroyApp(boolean unconditional)

private FormgetInfo(java.lang.String url)

    Form form = new Form("HTTP Info");
    HttpConnection connection = null;
    try {
        connection = (HttpConnection) Connector.open(url);
        connection.setRequestMethod("HEAD");
        for (int i = 0; ; i++) {
            String key = connection.getHeaderFieldKey(i);
            String value = connection.getHeaderField(i);
            if (value == null) break;
            if (key != null) form.append(key + ": " + value + "\n");
            else form.append("***" + value + "\n");;
        }
    }
    catch (Exception ex) {
       form.append(ex.getMessage() +"\n");
    }
   finally {
      try {
        if (connection != null) connection.close();
      }
      catch (IOException ex) { /* Oh well. we tried.*/ }
    }
 
    return form;
  
protected voidpauseApp()

public voidstartApp()

    display = Display.getDisplay(this);

    if (textBox == null) {
      textBox = new TextBox("URL", "http://", 255, TextField.URL);
    }
    display.setCurrent(textBox);

    Command getInfo = new Command("HTTP Headers", Command.OK, 10);
    textBox.addCommand(getInfo);
    textBox.setCommandListener(this);