-1
안녕 얘들 아 나는 프론트 엔드에 대한 백엔드와 자바에 대한 mysqli과 PHP를 사용하여 등록 페이지를 만들려고 해요. 내 PHP 연결 파일은 심지어 데이터를 삽입했습니다. 삽입하지 않으면 로그에 오류가 표시되지 않는 안드로이드 애플리케이션을 사용하여 데이터를 삽입하려고 시도합니다.안드로이드 MySQL 연결 오류
나는 안드로이드에서 Begginer입니다. 오류를 발견하면 용서해주세요.
여기 여기 내 HttpURLConnection의 파일이 여기 내 등록 페이지
b1 = (Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
str_email = "a";
str_password = "a";
str_full_name = "a";
str_registration_num = "a";
str_contact_number = "a";
new InsertData().execute();
}
});
private class InsertData extends AsyncTask<String, Void, String> {
String JSON_STRING;
JSONObject jsonObject = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
}
@Override
protected String doInBackground(String... params) {
JSONParser rh = new JSONParser();
HashMap<String, String> data = new HashMap<>();
data.put("email", str_email);
data.put("password", str_password);
data.put("full_name", str_full_name);
data.put("registration_num", str_registration_num);
data.put("contact_num", str_contact_number);
JSON_STRING = rh.sendPostRequest(AppConfig.URL_REGISTER, data);
return JSON_STRING;
}
}
public String sendPostRequest(String requestURL,
HashMap<String, String> postDataParams) {
//Creating a URL
URL url;
//StringBuilder object to store the message retrieved from the server
StringBuilder sb = new StringBuilder();
try {
//Initializing Url
url = new URL(requestURL);
//Creating an httmlurl connection
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//Configuring connection properties
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
//Creating an output stream
OutputStream os = conn.getOutputStream();
//Writing parameters to the request
//We are using a method getPostDataString which is defined below
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
sb = new StringBuilder();
String response;
//Reading server response
while ((response = br.readLine()) != null){
sb.append(response);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> entry : params.entrySet()) {
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
}
return result.toString();
}
응용 프로그램을 디버깅 했습니까? –
그래, 내가 그랬어 – user7828682
java.net.SocketException : sendto 실패 : EPIPE (브로큰 파이프). 그것은 디버깅하는 동안이 오류를 보여줍니다. – user7828682