import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class HttpConnect implements Runnable {
private Thread thread;
private String URL;
public HttpConnect(String url) {
thread = new Thread(this);
thread.start();
this.URL = url;
}
synchronized private void connectUrl() {
String message = "";
try {
HttpConnection hc = null;
InputStream in = null;
hc = (HttpConnection)Connector.open(this.URL);
in = hc.openInputStream();
int ch;
while((ch = in.read()) != -1)
message = message + (char) ch;
Store.resultantMessage = message.trim();
in.close();
hc.close();
hc = null;
in = null;
thread = null;
} catch (IOException ex) {
System.out.println("Unable to create " + URL + ": "+ex.getMessage());
}
}
public void run() {
connectUrl();
}
}
Users browsing this forum: No registered users and 2 guests