0
val params = RequestParams()
params.put("userid", prefs!!.getLong("userid", 0))
params.put("lastid", lastID)

val client = AsyncHttpClient()
client.post("$domain/xxx.php", params, object : JsonHttpResponseHandler() {

    override fun onSuccess(statusCode: Int, headers: Array<Header>?, response: JSONArray?) {

    }
    override fun onFailure(statusCode: Int, headers: Array<Header>?, e: Throwable, response: JSONArray?) {

    }
})

It works on API 26 but not on 23, apparently ssl url is the problem.

The solution here: how to make HTTPS calls using AsyncHttpClient?

isn't working, apparently because SSLSocketFactory is deprecated since API 22.

Then I tried using volley but it's a bad alternative because for what ever reasons you can't send POST parameters when receiving JSONArray.

Is there a solution?

  • "because SSLSocketFactory is deprecated since API 22" -- the relevant `SSLSocketFactory` [is not deprecated](https://developer.android.com/reference/javax/net/ssl/SSLSocketFactory). Conversely, `AsyncHttpClient` itself *is* deprecated [according to its GitHub project](https://github.com/android-async-http/android-async-http#this-project-under-develop-and-is-currently-insecure-to-use). "Is there a solution?" -- OkHttp is very popular. – CommonsWare Jun 19 '20 at 23:01
  • There is a lot of [documentation for OkHttp](https://square.github.io/okhttp), including a page of [recipes](https://square.github.io/okhttp/recipes/). Those include [using `POST` parameters](https://square.github.io/okhttp/recipes/#posting-form-parameters-kt-java). OkHttp will not parse the response for you, but there are lots of JSON parsers to choose from, such as Moshi or Gson. – CommonsWare Jun 19 '20 at 23:18

0 Answers0