j2me联网测试2014-10-20 16:50:36

( 3人已投票,[高质量] )
分享:
31.3K

j2me联网测试:

import java.io.DataInputStream;
       
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
       
       
public class Test7_1Http extends MIDlet {
private Form form = null;
private Display display = null;
  public Test7_1Http() {
    form = new Form("连网测试");
    display = Display.getDisplay(this);
  }
  protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
  }
       
  protected void pauseApp() {
  }
       
  protected void startApp() throws MIDletStateChangeException {
    try {
      HttpConnection connection = (HttpConnection)Connector.open("http://localhost:8080/pdsu.html");
             
      System.out.println(connection.getResponseCode());//得到连接状态
      System.out.println(connection.getResponseMessage());//得到连接响应的消息
             
      System.out.println(connection.getHost());//得到主机地址
      System.out.println(connection.getPort());//得到连接的断口号
      System.out.println(connection.getProtocol());//得到连接的协议
      System.out.println(connection.getURL());
      System.out.println(connection.getRequestMethod());//得到连接方式   默认get
             
      DataInputStream dis = connection.openDataInputStream();
       byte message[];
       int length = (int)connection.getLength();
       message = new byte[length];
       dis.readFully(message);
       form.append(new String(message));
       display.setCurrent(form);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
       
}






头像

snowcoal
  • j2me
  • 联网测试

本文标签:

j2me联网测试

收藏到我的私密空间

标题:j2me联网测试

作者:柳岸花明

你暂未登录,请登录后才可收藏至您的私密空间 确认取消
雪炭网

键盘操作 更便捷 -雪炭网雪中送炭-乐趣无限