Я хочу отобразить форму с 2 входами для электронной почты и пароля. В моем макете это:
<EditText
android:id="@+id/loginEmail"
android:hint="Your email..."
android:inputType="textEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/logo" />
<EditText
android:id="@+id/loginPassword"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/loginEmail"
android:autofillHints="" />
<TextView
android:id="@+id/loginBtn"
android:text="Login"
app:layout_constraintTop_toBottomOf="@+id/loginPassword" />
<TextView
android:id="@+id/loginSignupBtn"
android:text="Register"
app:layout_constraintTop_toBottomOf="@+id/loginBtn" />
Я попробовал вызов API на почтальоне, и он отлично работает ... У меня есть заголовок ответа, который содержит userId и токен-носитель.
В методе onCreate я создал прослушиватель кликов для входа в систему и создания новой учетной записи
loginBtn.setOnClickListener{
val url = Constants.url + "/login"
// to checkout
textView.text = ""
val userLoginRequest = UserLoginAndCreateRequestModel(
loginEmail.text.toString(),
loginPassword.text.toString()
)
val params = JSONObject()
params.put("email", userLoginRequest.email)
params.put("password", userLoginRequest.password)
// Volley post request with parameters
val request = JsonObjectRequest(
Request.Method.POST, url, params,
Response.Listener { response ->
// Process the json
try {
textView.text = "Response: $response"
Log.d(TAG, "Response: $response" )
// intent here
}catch (e:Exception){
Log.d(TAG, "Exception: $e")
textView.text = "Exception: $e"
}
}, Response.ErrorListener{
// Error in request
textView.text = "Volley error: $it"
Log.d(TAG, "Volley error: $it" )
}
)
Log.d(TAG, request.toString())
// Volley request policy, only one time request to avoid duplicate transaction
request.retryPolicy = DefaultRetryPolicy(
Constants.DEFAULT_TIMEOUT_MS,
// 0 means no retry
0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
)
// Add the volley post request to the request queue
VolleySingleton.getInstance(this).addToRequestQueue(request)
Моя проблема в том, что когда я запускаю этот код с мобильного , Я вызываю свой API, и мой API возвращает правильный ответ. Кажется, что я не получаю ответ и получаю сообщение об ошибке:
Вот мой лог-код:
2020-05-25 09:16:39.255 4318-4318/eu.xxx.photoapp D/MainActivity: eu.davidvera.photoapp.ui.model.request.UserLoginAndCreateRequestModel@1a11626
2020-05-25 09:16:39.255 4318-4318/eu.xxx.photoapp D/MainActivity: Login details : david.vera999@9online.fr 123
2020-05-25 09:16:39.260 4318-4318/eu.xxx.photoapp D/MainActivity: [ ] http://172.18.41.97:8080/rest-app/users/login 0x96b0528a NORMAL null
2020-05-25 09:16:39.289 4318-4394/eu.xxx.photoapp D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
2020-05-25 09:17:04.410 4318-4394/eu.xxx.photoapp D/Volley: [248] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://172.18.41.97:8080/rest-app/users/login 0x96b0528a NORMAL 1> [lifetime=25129], [size=0], [rc=200], [retryCount=0]
2020-05-25 09:17:04.414 4318-4318/eu.xxx.photoapp D/MainActivity: Volley error: com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of