Witam,
Mam problem z wykonaniem drugiej motody post w moim programie. Pojawia się ten błąd
E/Volley: [228] BasicNetwork.performRequest: Unexpected response code 403 for http://laude.ct8.pl/api/user/data/aktualizacja/
Błąd pojawia się tylko podczas wywoływanie drugiej metody POST, pierwsza wywoływana jest podczas logowania, do widoku onCreate dodałem również CookieHandler, poniżej kod.
CookieHandler.setDefault(CookieManager())
Kod do widoku logowania, który działa poprawnie:
private fun login2() {
val req = object : StringRequest(Request.Method.POST,
LOGIN_API_URL,
Response.Listener { response ->
Toast.makeText(this, response, Toast.LENGTH_LONG).show()
val user = Intent(this, UserActivity::class.java)
startActivity(user)
}, Response.ErrorListener { e ->
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
}) {
public override fun getParams(): Map<String, String> {
val params = HashMap<String, String>()
params.put("username", username.text.toString())
params.put("password", passwd.text.toString())
return params
}
override fun getBodyContentType(): String {
return "application/x-www-form-urlencoded";
}
}
req.retryPolicy = DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
volleyRequest!!.add(req)
}
Kod drugiego widoku, który nie działa już poprawnie:
private fun aktualizacja2() {
val req = object : StringRequest(Request.Method.POST,
UPDATE_URL,
Response.Listener { response ->
Toast.makeText(this, response.toString(), Toast.LENGTH_LONG).show()
}, Response.ErrorListener { e ->
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
}) {
public override fun getParams(): Map<String, String> {
val params = HashMap<String, String>()
params.put("librus_user", usernameEdit.text.toString())
params.put("librus_pswd", passwordEdit.text.toString())
return params
}
override fun getBodyContentType(): String {
return "application/x-www-form-urlencoded";
}
// @Throws(AuthFailureError::class)
// override fun getHeaders(): Map<String, String> {
// val headers = HashMap<String, String>()
// headers.put("Content-Type", "application/json; charset=utf-8")
// return headers
// }
}
req.retryPolicy = DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
volleyRequest!!.add(req)
}
Linki oraz dane dla osób które chcą to sprawdzić to u siebie:
Login: http://laude.ct8.pl/api/user/login/
Dane: username: fakeUser password: fakeUser
Drugi widok: http://laude.ct8.pl/api/user/data/aktualizacja/
Dane: librus_user: fake librus_pswd: fakePassword
Pozdrawiam oraz z góry dziękuję za pomoc.