안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요, 안드로이드와 php 연동 질문인데요.
클라이언트에서 서버로 HttpURLConnection 객체를 활용해서 POST로 데이터를 보냅니다.
그리고 서버에서는 해당 값을 받고 검사를 한 후 페이지를 띄웁니다.
해당 페이지가 exit.php 로 가정했을떄
exit.php 에는
echo "success" 밖에없는데도 안드로이드에서 로그를 찍어보면 저런식으로 받아집니다..ㅠㅠ
로그를 받는 부분이
InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "EUC-KR");
BufferedReader reader = new BufferedReader(tmp);
StringBuilder builder = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) { // 서버에서 라인단위로 보내줄 것이므로 라인단위로 읽는다
builder.append(str + "\n"); // View에 표시하기 위해 라인 구분자 추가
}
result = builder.toString();
Log.i("result",result);
이 부분인데요. 혹시 제가 잘못한 부분이나 실수한 부분이 있나요 ㅠㅠ? 아시는 분 있다면 좀 설명해주세요.
04-20 19:28:32.895: I/result(6157): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04-20 19:28:32.895: I/result(6157): <html xmlns="http://www.w3.org/1999/xhtml">
04-20 19:28:32.895: I/result(6157): <head>
04-20 19:28:32.895: I/result(6157): <title> DANAL TMobile </title>
04-20 19:28:32.895: I/result(6157): <meta http-equiv="Content-Type" content="text/html;charset=euc-kr" />
04-20 19:28:32.895: I/result(6157): <meta http-equiv="Cache-Control" content="no-cache" />
04-20 19:28:32.895: I/result(6157): <meta http-equiv="Pragma" content="no-cache" />
04-20 19:28:32.895: I/result(6157): <link rel="stylesheet" href="./style.css" type="text/css">
04-20 19:28:32.895: I/result(6157): <script type="text/javascript">
04-20 19:28:32.895: I/result(6157): </script>
04-20 19:28:32.895: I/result(6157): <style type="text/css">
04-20 19:28:32.895: I/result(6157): </style>
04-20 19:28:32.895: I/result(6157): </head>
04-20 19:28:32.895: I/result(6157): <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
04-20 19:28:32.895: I/result(6157): <body>
04-20 19:28:32.895: I/result(6157): <form name="next" action="exit.php" >
04-20 19:28:32.895: I/result(6157): </form>
04-20 19:28:32.895: I/result(6157): <script Language="Javascript">
04-20 19:28:32.895: I/result(6157): document.next.submit();
04-20 19:28:32.895: I/result(6157): </script>
04-20 19:28:32.895: I/result(6157): <!-- <form name="GoDeliver" action="./Deliver2.php" method="post"> -->
04-20 19:28:32.895: I/result(6157): // <INPUT TYPE="HIDDEN" NAME="Info" value="|TelNum=111111|Iden=111111">
04-20 19:28:32.895: I/result(6157): <!-- </form> -->
04-20 19:28:32.895: I/result(6157): <!-- <script> -->
04-20 19:28:32.895: I/result(6157): document.GoDeliver.submit();
04-20 19:28:32.895: I/result(6157): <!-- </script> -->
2012.04.21 17:54:22
echo 를 통해 출력됀값만 받아오고싶어하시는듯하군요.
이건 안드로이드문제가 아니라 요청된 결과값이 저럴수밖에없을겁니다.
한예로 A문서에서 AJAX 비동기화방식으로 B문서에 요청하여 결과값을 가져올때(html문법과 php echo 코드가 복합적으로 있을때)
HTML문법이 포함되있으면 싸그리 가져옵니다.
해당 문서에 echo "hi"; 만 써보세요. 로그에 hi만 찍혀있을듯하네요.
파싱하지않고 요청된 결과값을 GET요청(name=me&phone=010)방식으로 받아와 처리하는 방식이 존재하는데요.
개발자 정보게시물에 한번 올려볼게요.
저렇게 받아오는게 정상 아닌가요,
결과 텍스트를 웹에서 XML로 생성하신다음에
받아오신다음 거기서 파싱 해오시는건데...