因此,我正在学习Udacity Android App Developer课程,并且代码解释得不好。因此,这是关于Http请求的。扫描仪在这里做什么? \ A分隔符是什么?为什么要返回scanner.next()?什么是Disconnect()方法?
public static String getResponseFromHttpUrl(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = urlConnection.getInputStream();
Scanner scanner = new Scanner(in);
scanner.useDelimiter("\\A");
boolean hasInput = scanner.hasNext();
if (hasInput) {
return scanner.next();
} else {
return null;
}
} finally {
urlConnection.disconnect();
}
}