Java Reference
In-Depth Information
public WeatherFetcher(Location l, WeatherWidget a) {
location = l;
app=a;
cancelled = false;
if (l!=null && a!=null) {
thread = new Thread(this);
thread.start();
}
}
public void cancel() {
cancelled = true;
}
public void run() {
String vars;
String forecast = "";
HttpConnection hc = null;
InputStream in = null;
OutputStream out = null;
vars = "location="+WeatherFetcher.urlEncode(location.getLocation());
try {
hc = (HttpConnection)Connector.open(url);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("Content-Type",
"application/x-www-formrlencoded");
hc.setRequestProperty("Content-Length",
Integer.toString(vars.length()));
out=hc.openOutputStream();
out.write(vars.getBytes());
in=hc.openInputStream();
int length=(int)hc.getLength();
byte[] data = new byte[length];
in.read(data);
forecast = new String(data);
}
 
Search WWH ::




Custom Search