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();
}
}
我正在mainActivity的doinbackground方法内的异步任务中调用此函数,但它始终返回null。当我尝试调试时,hasInput为true ..任何建议?? TIA。