http 요청을 보내고 해당 요청에서 문자열을 반환하고 싶습니다.URL에서 텍스트를 가져 오는 Android가 항상 NULL입니다.
현재이 코드를 사용하고 있지만 URL이 무엇이든 관계없이 항상 null이 표시됩니다. 그게 무슨 문제 야?
시도 { // 원하는 페이지 URL의 URL에 대한 URL = 새 URL을 생성 ("HTTP : // 호스트 이름 : 80/index.html을");
// Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { // str is one line of text; readLine() strips the newline character(s) } in.close(); } catch (MalformedURLException e) { } catch (IOException e) { }
코드 것은 잘 작동 적절한 URL을 제공하십시오. . Android에서이 작업을 수행하려고 할 때 AndroidManifest.xml에서 적절한 인터넷 권한을 설정 했습니까? – Darwind
AndroidManifest.xml에 인터넷 사용 권한을 추가했습니다. 나는 적절한 URL을주지 만, 매번 null을 얻는다. – user1319668
당신은 어떤 URL을 제공하고 있습니까? – Darwind