Unable to Parse Tls Packet Header Android Studio

I want to connect my local server and get some data with Retrofit but I gave the error "Unable to parse TLS packet header" and I couldn't solve this problem please give me a solution

onFailure: Unable to parse TLS packet header

ServiceBuilder.kt

object ServiceBuilder {
    private val client = OkHttpClient.Builder()
        .connectionSpecs(listOf(ConnectionSpec.MODERN_TLS) )
        .build()

    private val retrofit = Retrofit.Builder()
        .baseUrl(Config().BASE_URL)# ""
        .addConverterFactory(GsonConverterFactory.create())
        .client(client)
        .build()

    fun<T> buildService(service: Class<T>): T{
        Security.insertProviderAt(Conscrypt.newProvider(), 1);
        return retrofit.create(service)
    }
}

LinesrsEndpoint.kt

interface LinesrsEndpoint{
    @GET("/getAllLinesrs")
    fun getLinesrs(): Call<AllLinesrs>
}

LinesRs.kt

data class AllLinesrs(val results:List<Linesrs>)

data class Linesrs(
    var lineId: Int,
    var symbolId: String,
    var lineStart: String,
    var lineEnd: String,
    var lineTimeFrame: String,
    var lineInsertTime: String,
    var lineSensDgre: String,
    var linesrsGroupId: String,
    var userId: String,
    var user: User

)

MainActivity.kt

class MainActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_trend_line)

        val request = ServiceBuilder.buildService(LinesrsEndpoint::class.java)
        val call = request.getLinesrs()

        call.enqueue(object : Callback<AllLinesrs> {
            override fun onResponse(call: Call<AllLinesrs>, response: Response<AllLinesrs>) {
                if (response.isSuccessful) {
                    Log.e("hamid", "onResponse: "+response.body() )
                }
            }

            override fun onFailure(call: Call<AllLinesrs>, t: Throwable) {
                Log.e("hamid", "onFailure: " + t.message)
            }
        })
    }

}
1

1 Answer

Try this: change base URL from https to http.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest