客户端:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import javax.microedition.io.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.io.file.*;
public HttpConnect extends MIDlet {
public HttpConnect {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp {
// TODO Auto-generated method stub
}
protected void startApp throws MIDletStateChangeException{
String url = "http://192.168.0.114:8080/EngineService/sync";
try{
data = null;
( .getProperty("microedition.io.file.FileConnection.version" ) != null ){
try {
FileConnection fc = (FileConnection)Connector.open("file:///root1/test.png", Connector.READ_WRITE);
//fc.create;
InputStream in = fc.openInputStream;
fc.close;
ByteArrayOutputStream out = ByteArrayOutputStream(4096);
tmp = [4096];
n;
while ((n = in.read(tmp)) != -1) {
out.write(tmp, 0, n);
out.flush;
}
in.close;
out.close;
data = out.toByteArray;
}catch (Exception e) {
e.prStackTrace;
}
}
HttpConnection sc = (HttpConnection)Connector.open( url, Connector.READ_WRITE, true );
sc.RequestMethod( HttpConnection.POST );
sc.RequestProperty("Content-Type", "application/octet-stream");
sc.RequestProperty("Content-Length", String.valueOf(data.length));
OutputStream output = sc.openOutputStream;
output.write(data);
output.flush;
output.close;
}catch(Exception e){
.out.prln("Error:"+e);
}
}
}
服务器端:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
InputStream in = req.getInputStream;
tmp = [4096];
size=0;
File f = File("c:\\",.currentTimeMillis+".png");
DataOutputStream o = DataOutputStream( FileOutputStream(f));
len=0;
while((len = in.read(tmp))!= -1){
o.write(tmp,0,len);
o.flush;
sizelen;
}
o.close;
}
本文来自CSDN博客转载请标明出处:http://blog.csdn.net/jxst051665/archive/2009/07/15/4349714.aspx
最新评论