I want to send my HTTP requests with an Authorization header that contains the word Basic followed by a space and a base64-encoded string {{Username}}:{{Password}} Example Authorization: Basic YWRtaW46MTIzNDU2 Body Params (application/form-data) grant_type string optional Example: client_credentials

I have clientId and SecretId , below is my code but it doesn't work. Can any one help me to send this reqwest and get response(json)

access_token string required expires_in integer required token_type string required scope string

below is my code:

binding.noAccount.setOnClickListener{

        val url = "https://api.name.bi/oAuth2/token/"
        val client= OkHttpClient.Builder().build()
        val ClientId = "NrOHKgtyGFue5CX"
        val SecretId = "QGrugSLVXHOZa5RRFZdWnvQ2dTKW"
        val credential = Credentials.basic("$ClientId", "$SecretId")

        val RequestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
            .addFormDataPart("grant_type", "$credential")
            .build()

        val request = Request.Builder()
            .url(url)
            .header("content-type", "multipart/form-data")
            .post(RequestBody)
            .build()


        client.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                e.printStackTrace()
            }

            override fun onResponse(call: Call, response: Response) {
                Log.i("onResponse"," reponse")
                response.use { if (!response.isSuccessful){
                    Log.e( "onResponse: ", " non satisfaisant")

                } else {
                    val body= response.body?.string()
                    binding.forgotPassword.text=body   //forgot is a textView here i want to display joson response
                }
                }

            }
        })
0

There are 0 answers