我正在编写一个应用程序,其中的模型对象将公开一些Web服务的Restful接口。我注意到在Android中有java.net.URI和android.net.URI类。使用其中之一有什么好处?是否有人遇到过这种情况,并发现其中一个比另一个更好?
在下面的代码中,我将URI的各个部分解析为java.net URI对象,以便我可以调用
在下面的代码中,我将URI的各个部分解析为java.net URI对象,以便我可以调用
httpGet(URI uri)
。但是,使用android.net类或只调用httpGet(String url)是否有任何性能优势或任何好处?public class RestMethods {
private String protocol;
private String host;
private Integer port;
private URI uri;
public String restGet(String path) throws MalformedURLException, InterruptedException, ExecutionException{
StringBuilder builder = new StringBuilder();
try {
// Execute HTTP Post Request
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(uri);
HttpResponse response = httpclient.execute(httpget);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
} catch (ClientProtocolException e) {
return "Client Protocol Exception Exception " + e.toString();
} catch (IOException e) {
return "IO Exception " + e.toString();
}
return builder.toString();
}
...
//Other rest methods, Getters, and setters down here
...
}