国产探花免费观看_亚洲丰满少妇自慰呻吟_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://m.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 太白县| 巨鹿县| 沁阳市| 襄汾县| 高密市| 五华县| 胶州市| 邓州市| 广州市| 灵川县| 桐庐县| 绵竹市| 淳安县| 老河口市| 乌兰察布市| 汉寿县| 清苑县| 浮梁县| 蒲城县| 丹阳市| 江门市| 玉溪市| 冀州市| 射阳县| 伊金霍洛旗| 东平县| 边坝县| 福海县| 塔城市| 灵台县| 库尔勒市| 日喀则市| 刚察县| 韩城市| 武陟县| 洛南县| 鄂伦春自治旗| 耒阳市| 灵石县| 郴州市| 什邡市|