Java Reference
In-Depth Information
private String requestEncode() {
StringBuffer result = new StringBuffer();
result.append(url);
result.append(urlEncode(location.getLocation()));
return result.toString();
}
public void run() {
String requestUrl;
String response = "";
HttpConnection hc = null;
InputStream in = null;
requestUrl = requestEncode();
try {
hc = (HttpConnection)Connector.open(requestUrl);
hc.setRequestMethod(HttpConnection.GET);
in=hc.openInputStream();
int length=(int)hc.getLength();
byte[] data = new byte[length];
in.read(data);
response = new String(data);
}
catch(Exception e){}
finally {
try {
if (in!=null) in.close();
if (hc!=null) hc.close();
}
catch(Exception e) {}
}
if (!cancelled) {
location.fromXml(response);
app.update();
}
}
}
Recall that in a REST service, URLs represent objects, and HTTP methods represent
verbs that act on those objects. Thus, the weather service's URL is really a prefix to a spe-
cific object; accessing the web service for the weather in Berkeley, California, the
application might generate this URL:
http://www.noplace.com/location/Berkeley%2C%20CA%2C%20USA
 
Search WWH ::




Custom Search