Open KangHoyong opened 8 years ago
NameValuePair error 해결 방법 -> Map 사용
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("name", user.name));
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS + "Register.php");
try{
post.setEntity(new UrlEncodedFormEntity(dataToSend));
}catch (Exception e)
{
e.printStackTrace();
}
수정 내용
// Use HashMap, it works similar to NameValuePair
Map<String, String> dataToSend = new HashMap<>();
dataToSend.put("email", user.mail);
dataToSend.put("password", user.password);
dataToSend.put("name",user.name);
dataToSend.put("phoneNumber", user.phoneNumber);
dataToSend.put("birthData",user.birthDate);
// 수정
String encodedStr = getEncodedData(dataToSend);
BufferedReader reader = null;
// Connection Handling
try {
// Convertion address String to URL
URL url = new URL(SERVER_ADDRESS + "Register.php");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Post Method
con.setRequestMethod("POST");
// To enable inputting values using POST method
con.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
// Writing dataToSend to outputstream wirter
writer.write(encodedStr);
//Sending the data to the server - This much is enough to send data to server
//But to read the response of the server, you will have to implement the procedure below
writer.flush();
//Data Read Procedure - Basically reading the data comming line by line
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = reader.readLine()) !=null)
{
// Read till there is something available
sb.append(line + "\n");
}
line = sb.toString();
//Just check to the values received in Logcat
Log.i("custom_check","The values received in the store part are as follows:");
Log.i("custom_check",line);
} catch (Exception e){
e.printStackTrace();
} finally {
if(reader != null){
try{
reader.close(); // Closing the
} catch (IOException e) {
e.printStackTrace();
}
}
}
OS MySQL mysql.server start mysql -h localhost -u root -p
show databases; 데이터 베이스 목록보기 use 데이터 베이스 이름 ; show tables;
android register success ~~!!
There’s a lot of extra work........