안녕하세요.
안드로이드에서 php에 값을 넘겨서 ? php에서 mysql 데이터 읽어오고 이걸 xml로 만들려고 하는데
앱에서 php 호출을 못하는 것 같습니다. button을 누르면
LogInPost(); 를 통해 아래 메서드? 를 호출하는데
직접 php에 id, password를 넣을경우 xml이 생성되는데 앱으로 돌려보면 생성조차 안되는 걸 보면 php를 못읽는거 같아요.
public void LogInPost() {
// TODO Auto-generated method stub
try {
URL url = new URL("http://163.239.98.40/xmltest/insert.php");
HttpURLConnection http = (HttpURLConnection) url.openConnection(); // 접속
//--------------------------
// 전송 모드 설정 - 기본적인 설정이다
//--------------------------
http.setDefaultUseCaches(false);
http.setDoInput(true); // 서버에서 읽기 모드 지정
http.setDoOutput(true); // 서버로 쓰기 모드 지정
http.setRequestMethod("POST"); // 전송 방식은 POST
// 서버에게 웹에서 <Form>으로 값이 넘어온 것과 같은 방식으로 처리하라는 걸 알려준다
http.setRequestProperty("content-type", "application/x-www-form-urlencoded");
//--------------------------
// 서버로 값 전송
//--------------------------
StringBuffer buffer = new StringBuffer();
buffer.append("id").append("=").append(userid).append("&");
// php 변수에 값 대입
buffer.append("password").append("=").append(userpwd);
OutputStreamWriter outStream = new OutputStreamWriter(http.getOutputStream(), "utf8");
Log.d("check", "1" + userid);
PrintWriter writer = new PrintWriter(outStream);
Log.d("check", "2");
writer.write(buffer.toString());
writer.flush();
Log.d("check", "3");
Toast.makeText(getApplicationContext(), "php접속완료", Toast.LENGTH_SHORT).show();
}
catch(Exception e){}
}