📄 httpthread.java
字号:
package com.wy.ch11;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class HTTPThread extends Thread{
private TextBox tb;
public HTTPThread(TextBox t) {
tb=t;
}
public void run(){
HttpConnection hc=null;
String url="http://127.0.0.1/test.html";
InputStream is=null;
StringBuffer buffer=new StringBuffer();
String result="";
try{
hc=(HttpConnection)Connector.open(url);
String host=hc.getHost();
System.out.println("服务器地址是:"+host);
int port=hc.getPort();
System.out.println("服务器端口是:"+port);
String protocol =hc.getProtocol();
System.out.println("网络协议是:"+protocol);
String serverurl=hc.getURL();
System.out.println("服务器URL是:"+serverurl);
int status=hc.getResponseCode();
if(status==HttpConnection.HTTP_OK){
is=hc.openInputStream();
int ch;
while((ch=is.read())!=-1){
buffer.append((char)ch);
}
result=buffer.toString();
result = new String(result.getBytes("iso-8859-1"),"gb2312");
tb.setString(result);
}//if
}catch(Exception e){
} finally{
try{
if(is!=null){
is.close();
}
if(hc!=null){
hc.close();
}
}catch(Exception e){
}
}//finally
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -