我正在编写一个带有模型对象的应用程序,它将Restful接口暴露给某些Web服务.我注意到在Android中有一个java.net.URI和一个android.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
...
}
Run Code Online (Sandbox Code Playgroud)