Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ExHttp.java
Package: J2ME&Game.rar [view]
Upload User: gyyuli
Upload Date: 2013-07-09
Package Size: 3050k
Code Size: 3k
Category:
J2ME
Development Platform:
Java
- 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));
- */
- //设置请求为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();//打开输入流
- int ch;
- StringBuffer buf = new StringBuffer(100000);
- while((ch=is.read())!=-1)
- {
- //处理数据
- 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);
- }
- }
- }