내 Android 앱에서 웹 페이지 콘텐츠를 가져 오는 데 문제가 있습니다. 나는이 주소 https://szr.szczecin.pl/utms/data/layers/VMSPublic에서 내용을 읽고 싶다. 안드로이드에서 웹 페이지 콘텐츠를 얻는 방법?
는 처음에 나는이 코드를 사용하여 Java에서 그것을 할 시도 : I 다운로드 및 해당 웹 페이지에서 인증서를 설치 한 후 근무public class Main {
public static void main(String[] args) {
String https_url = "https://szr.szczecin.pl/utms/data/layers/VMSPublic";
URL url;
try {
url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
print_content(con);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void print_content(HttpsURLConnection con) {
if (con != null) {
try {
System.out.println("****** Content of the URL ********");
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String input;
while ((input = br.readLine()) != null) {
System.out.println(input);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
. Android에서 어떻게 똑같이 할 수 있습니까? 안드로이드에서 HTTPSURLConnection 시도했지만 웹 페이지의 주소 만 반환합니다. HTTPURLConnection을 시도 할 때 문서가 이동되었다는 정보를 제공합니다 (상태 302).
이 기능은 주 스레드에서 실행할 수 없으므로 오류가 발생합니다. 스레드를 확장하거나 비동기로 구현하는 클래스에서 삭제하십시오. 두 가지 예제는 http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – RelicScoth
모두 사용 중지되었습니다. –