함수 url_get_contents()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:49 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
함수 url_get_contents()

1 Java[ | ]

private static String url_get_contents(String urlstr) {
	String content = null;
	try {
		URL url = new URL(urlstr);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.getResponseCode();
		InputStream stream = connection.getErrorStream();
		if (stream == null) stream = connection.getInputStream();
		Scanner scanner = new Scanner(stream);
		scanner.useDelimiter("\\Z");
		content = scanner.next();
		scanner.close();
	}
	catch (MalformedURLException e) { e.printStackTrace(); }
	catch (IOException e) { e.printStackTrace(); }
	return content;
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}