개발자였던 것/Spring
[Ajax/Servlet] 다른 서버의 파일을 내 서버로 복사하는 코드
서으이
2020. 6. 30. 11:40
728x90
반응형
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out=response.getWriter();
HttpURLConnection conn=null;
String str="http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108";
//사이트연결 객체 생성
URL url=new URL(str);
//사이트 연결해서 결과값리턴
conn=(HttpURLConnection)url.openConnection();
BufferedInputStream is
=new BufferedInputStream(conn.getInputStream());
byte[] b =new byte[4096];//2 4 8 16 1024 2048 4096
StringBuffer buffer=new StringBuffer();
int i;
while( (i = is.read(b)) != -1){
buffer.append(new String(b, 0, i));
}
String str2 = buffer.toString();
out.println(str2);
728x90
반응형