?? exhttp.java
字號(hào):
package exframework;
/**
* <p>Title: ExFramework</p>
*
* <p>Description: lizhenpeng</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: LP&P</p>
*
* @author lipeng
* @version 1.0
*/
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.lcdui.*;
public class ExHttp implements AllAction,Runnable
{
HttpConnection conn;
MainForm form;
public ExHttp()
{
}
public void allAction(MainForm form)
{
ExHttp http = new ExHttp();
http.form = form;
Thread t = new Thread(http);
t.start();
// conn=(HttpConnection)Connector.open("http://www.sina.com.cn");
// Set the request method and headers
/*
try
{
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("If-Modified-Since","31 Aug 2005 0:55:31 GMT");
conn.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
conn.setRequestProperty("Content-Language","en-US");
}
catch(Exception e)
{
}
StringBuffer sb=new StringBuffer(60);
sb.append("Configuration/");
sb.append(System.getProperty("microedition.configuration"));
String prof=System.getProperty("microedition.profiles");
int i=0;
int j=0;
while((j=prof.indexOf(' ',i))!=-1)
{
sb.append(" Profile/");
sb.append(prof.substring(i,j));
i=j+i;
}
sb.append(" Profile/");
sb.append(prof.substring(i));
*/
//設(shè)置請(qǐng)求為POST
/*
//conn.setRequestMethod(HttpConnection.POST);
// os=conn.openOutputStream();
// os.write("hello".getBytes());
// os.flush();
//int status=conn.getResponseCode();//判斷連接是否正常
if(status==HttpConnection.HTTP_OK)
{
is = conn.openInputStream();//打開(kāi)輸入流
int ch;
StringBuffer buf = new StringBuffer(100000);
while((ch=is.read())!=-1)
{
//處理數(shù)據(jù)
buf.append((char)ch);
}
System.out.println(buf);
}*/
}
public void run()
{
try
{
conn=(HttpConnection)Connector.open("http://localhost:8080/examples/images/bg.png");
InputStream in = conn.openInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int oneByte;
while((oneByte = in.read())!=-1)
{
baos.write(oneByte);
}
byte[] b = baos.toByteArray();
Image image = Image.createImage(b,0,b.length);
this.form.append(image);
if(in!=null)
{
in.close();
}
if(conn!=null)
{
conn.close();
}
}
catch(Exception e)
{
System.out.print(e);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -