⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpexamplemid.java

📁 自己做的有关网站相关参数的测试
💻 JAVA
字号:
import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.ContentConnection;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class HttpExampleMID extends MIDlet implements CommandListener {

	Command exit=null;
	TextBox tb=null;
	public String str=null;
	Ticker t=null;
	public HttpExampleMID()
	{
		exit=new Command("退出",7,1);
		tb=new TextBox("信息","",200,0);
		str="http://www.163.com";
	    t=new Ticker("哈哈哈哈");
		tb.addCommand(exit);
		tb.setCommandListener(this);
		
	}
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
 

	}

	protected void pauseApp() {
		
	}

	public void startApp() throws MIDletStateChangeException{
		HttpConnection httpconnection=null;
		StringBuffer stringBuffer=new StringBuffer();
		try {
 
			httpconnection=(HttpConnection)Connector.open(str);
//			this.platformRequest("http://www.163.com");
		 
//			getViaContentConnection("http://www.163.com");
			
		stringBuffer.append("Host主机名:"+httpconnection.getHost() + "\n"             //////获得此 URL 的主机名
				           +"Port端口号:"+httpconnection.getPort()   + "\n"            ///// 获得此 URL 的端口号
				           +"Date头字段:"+httpconnection.getDate()    + "\n"          ///// 返回 date 头字段的值
				           +"Encoding字符编码:"+httpconnection.getEncoding()  + "\n"    /////返回此流使用的字符编码的名称
				           +"Protocol协议名称:"+httpconnection.getProtocol()  + "\n"    /////获得此 URL 的协议名称
				           +"File文件名:"+httpconnection.getFile()         + "\n"     /////获得此 URL 的文件名
				           +"Tpye控件类型:"+httpconnection.getType() + "\n"             /////获得控件的类型
				           +"URL字段:"+httpconnection.getURL() + "\n"             /////返回此  URL 字段的值   
				           +"Ref锚点:"+httpconnection.getRef() + "\n"              /////获得此 getQuery URL 的锚点(也称为“引用”) 
				           +"Query查询部分:"+httpconnection.getQuery() + "\n"       ///// 获得此 URL 的查询部分。  
		);					
//		stringBuffer.append("Host: " + httpconnection.getHost() + "\n");
//		stringBuffer.append("Port: " + httpconnection.getPort() + "\n");
//		stringBuffer.append("Date: " + httpconnection.getDate() + "\n");
//		stringBuffer.append("Encoding: " + httpconnection.getEncoding() + "\n");
//		stringBuffer.append("Protocol: " + httpconnection.getProtocol() + "\n");
//		stringBuffer.append("File: " + httpconnection.getFile() + "\n");
//		stringBuffer.append("Type: " + httpconnection.getType() + "\n");
		
		} catch (IOException e) {
			e.printStackTrace();
		}		
		try {
			httpconnection.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		tb.setString(stringBuffer.toString());
	
	    tb.setTicker(t);
		Display.getDisplay(this).setCurrent(tb);
	}

    void getViaContentConnection(String url) throws IOException {
        ContentConnection c = null;
        DataInputStream dis = null;
        try {
            c = (ContentConnection)Connector.open(url);
            int len = (int)c.getLength();
            dis = c.openDataInputStream();
            if (len > 0) {
                byte[] data = new byte[len];
                dis.readFully(data);
                
            } else {
//                int ch;
//                while ((ch = dis.read()) != -1) {
//                   
//                }
            }
        } finally {
            if (dis != null)
                dis.close();
            if (c != null)
                c.close();
        }
    }
	
	public void commandAction(Command c, Displayable d) {
	 if(c==exit)
		 notifyDestroyed();
 
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -