Android(Kotlin)とLAMP環境のデータ挿入でHTTP Status Code: 500

Kotlinを使ってアプリのログイン画面を作成しています。
今回はMVCモデルを採用しており、下記DAOクラスの「insertIntoLoginTbl」関数を用いて先ずはユーザ登録を行いたいのですが、
下記エラーが返却されてしまいます。

エラー内容

[75] NetworkUtility.shouldRetryException: Unexpected response code 500 for http://192.168.0.109/userRegistrationInsert.php Error. HTTP Status Code: 500 com.android.volley.ServerError

バックエンドサーバの開発環境は以下の通りです。
今回はLAMPを用いて言います。
OS: Ubuntu Server 20.04
Apache: Apache/2.4.41 (Ubuntu)
MySQL: 8.0.32-0ubuntu0.20.04.2 for Linux on x86_64
PHP: PHP 8.1.14 (cli)

流れとしては、/var/www/androidに下記userRegistrationInsert.phpを用意しており、
こちらがAndroid端末から新規ユーザ情報を受け取るAPIとして機能しています。

-rw-rw-r-- 1 www-data www-data 1456 Jan 30 06:30 userRegistrationInsert.php

念の為、/etc/apache2/sites-available/000-default.confの内容も掲載しておきます。

DocumentRoot /var/www/android

BudgetTrackerUserDao.kt

package com.undeniabledreams.cloudbudgettracker.dao import android.content.Context import android.util.Log import android.widget.Toast import com.android.volley.AuthFailureError import com.android.volley.Response import com.android.volley.ServerError import com.android.volley.toolbox.StringRequest import com.android.volley.toolbox.Volley import com.undeniabledreams.cloudbudgettracker.core.BudgetTrackerUserDto import org.json.JSONException import org.json.JSONObject import java.io.IOException import java.util.* import kotlin.collections.HashMap class BudgetTrackerUserDao(context: Context) { private val context: Context = context.applicationContext fun insertIntoLoginTbl(budgetTrackerUserDto: BudgetTrackerUserDto): Int { try { val properties = Properties() val inputStream = context.assets.open("server_config.properties") properties.load(inputStream) val serverUrl = properties.getProperty("server_url") val phpInsertFile = properties.getProperty("insert_php_file") val insertUrl = "$serverUrl$phpInsertFile" Log.d("insert_url", insertUrl) val stringRequest = object : StringRequest( Method.POST, insertUrl, Response.Listener { response -> try { val jsonObject = JSONObject(response) val success = jsonObject.getString("success") if (success > 0.toString()) { Toast.makeText( context, "User data has been inserted", Toast.LENGTH_SHORT ).show() } } catch (e: JSONException) { Log.e("JSONException", e.toString()) e.printStackTrace() } }, Response.ErrorListener { error -> if (error is ServerError) { val networkResponse = error.networkResponse if (networkResponse != null) { Log.e( "Volley", "Error. HTTP Status Code: ${networkResponse.statusCode}" ) } } Toast.makeText(context, "Unable to insert data $error", Toast.LENGTH_SHORT) .show() Log.e("VolleyError", error.toString()) }) { @Throws(AuthFailureError::class) override fun getParams(): Map<String, String> { val params = HashMap<String, String>() params["user_name"] = budgetTrackerUserDto.getId() params["password"] = budgetTrackerUserDto.getPassword() return params } } val requestQueue = Volley.newRequestQueue(context) requestQueue.add(stringRequest) } catch (e: IOException) { e.printStackTrace() } return 0 } fun logIn(budgetTrackerUserDto: BudgetTrackerUserDto): Int { var result = 0 try { val properties = Properties() val inputStream = context.assets.open("server_config.properties") properties.load(inputStream) val serverUrl = properties.getProperty("server_url") val phpLoginFile = properties.getProperty("login_php_file") val loginUrl = "$serverUrl$phpLoginFile" Log.d("login_url", loginUrl) val stringRequest = object : StringRequest(Method.POST, loginUrl, Response.Listener { response -> try { val jsonObject = JSONObject(response) val success = jsonObject.getString("success") if (success == "1") { result = 1 } } catch (e: JSONException) { Log.e("JSONException", e.toString()) } }, Response.ErrorListener { error -> if (context != null) { Toast.makeText(context, "Unable to send data $error", Toast.LENGTH_SHORT).show() } Log.e("VolleyError", error.toString()) }) { @Throws(AuthFailureError::class) override fun getParams(): Map<String, String> { val params = HashMap<String, String>() params["user_name"] = budgetTrackerUserDto.getId() params["password"] = budgetTrackerUserDto.getPassword() return params } } val requestQueue = Volley.newRequestQueue(context) requestQueue.add(stringRequest) } catch (e: IOException) { e.printStackTrace() } return result } }

解決案をご提示いただける方がおられましたら、ご回答の程よろしくお願いいたします。

コメントを投稿

0 コメント