import java.io.DataInputStream;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.io.*;
public class 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?user=client";
try{
HttpConnection hpc = null;
DataInputStream dis = null;
boolean newline = false;
String content = "";
hpc = (HttpConnection)Connector.open(URL);
hpc.setRequestMethod(HttpConnection.GET);
dis = new DataInputStream(hpc.openInputStream());
int character;
while((character = dis.read())!= -1){
if((char)character=='//'){
newline=true;
continue;
}else{
if((char)character=='n'&&newline){
content += "/n";
newline = false;
}else if(newline){
content += "//"+(char)character;
newline = false;
}else{
content +=(char)character;
newline = false;
}
}
}
hpc.close();
hpc = null;
dis.close();
dis = null;
content = content.trim();
System.out.println(content);
}catch(Exception e){
System.out.println("Error:"+e);
}
}
}
J2ME版HttpConnect
最新推荐文章于 2017-09-06 13:37:49 发布