国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

MIDlet中使用https通信

2019-11-18 16:18:20
字體:
來源:轉載
供稿:網友
import java.io.*;

import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.pki.*;

public class HttpsMIDlet extends MIDlet
    implements CommandListener, Runnable {
  PRivate Display mDisplay;
  private Form mForm;
  
  public void startApp() {
    mDisplay = Display.getDisplay(this);
    
    if (mForm == null) {
      mForm = new Form("HttpsMIDlet");
  
      mForm.addCommand(new Command("Exit", Command.EXIT, 0));
      mForm.addCommand(new Command("Send", Command.SCREEN, 0));
      mForm.setCommandListener(this);
    }

    mDisplay.setCurrent(mForm);
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {}
  
  public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT) notifyDestroyed();
    else {
      Form waitForm = new Form("Connecting...");
      mDisplay.setCurrent(waitForm);
      Thread t = new Thread(this);
      t.start();
    }
  }

  public void run() {
    String url = getAppProperty("HttpsMIDlet-URL");

    try {
      // Query the server and retrieve the response.
      HttpsConnection hc = (HttpsConnection)Connector.open(url);
      
      SecurityInfo si = hc.getSecurityInfo();
      Certificate c = si.getServerCertificate();
      String subject = c.getSubject();

      String s = "Server certificate subject: /n" + subject;
      Alert a = new Alert("Result", s, null, null);
      a.setTimeout(Alert.FOREVER);
      mDisplay.setCurrent(a, mForm);

      hc.close();
    }
    catch (IOException ioe) {
      Alert a = new Alert("Exception", ioe.toString(), null, null);
      a.setTimeout(Alert.FOREVER);
      mDisplay.setCurrent(a, mForm);
    }
  }
}
進入討論組討論。

(出處:http://www.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 土默特左旗| 大新县| 田林县| 原平市| 时尚| 佳木斯市| 师宗县| 威远县| 玉屏| 陇西县| 井陉县| 兴文县| 富裕县| 呼和浩特市| 澜沧| 南雄市| 大庆市| 深泽县| 徐闻县| 邯郸市| 东山县| 蛟河市| 吉安市| 孙吴县| 湖南省| 宕昌县| 荥经县| 眉山市| 仙桃市| 大竹县| 哈尔滨市| 五台县| 涟源市| 垦利县| 光山县| 舒兰市| 图片| 泸水县| 民和| 石家庄市| 东兰县|