StringBuffer buffer = new StringBuffer();
try {
URL url= new URL(address);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (connection != null) {
connection.setDefaultUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setReadTimeout(10000);
connection.setConnectTimeout(10000);
connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
String data = URLEncoder.encode("id", "UTF-8") + "=" + URLEncoder.encode("gg", "UTF-8");
data += "&" + URLEncoder.encode("pw", "UTF-8") + "=" + URLEncoder.encode("zz", "UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(data);
wr.flush();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "euc-kr"));
for (;;) {
// 웹상에 보여지는 텍스트를 라인단위로 읽어 저장.
String line = br.readLine();
if (line == null) break;
// 저장된 텍스트 라인을 jsonHtml에 붙여넣음
buffer.append(line);
}
br.close();
}
connection.disconnect();
Message msg=mHandler.obtainMessage();
msg.what=0;
msg.arg1= Integer.parseInt(buffer.toString());
mHandler.sendMessage(msg);
//
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
<?php
$id=$_POST['id'];
$pw=$_POST['pw'];
mysql_connect('localhost','userid','userpwd');
mysql_select_db('dbname');
mysql_query("insert into member values('$id','$pw')");
?>
위에는 안드로이드에서 보내는 코드이고
밑에는 서버에서 받는 코드 입니다.
이걸 실행시키면 DB에 자꾸 빈칸만 들어가는데 이유를 알고싶습니다. ㅠ. 일주일 넘게 삽질중입니다...
추천 꼭 해드릴게요