i have a web service in this url : https://server_IP:9443/api/v1/ssids.json/ but it needs login in this page : https://server_IP:9443/login
when i make the request with the credentials in the headers , i got "Unexpected response code 401"
so how can i authenticate and get the json.
here is my code :
val request = object : StringRequest(Request.Method.GET, url, Response.Listener { response ->
if (response != null) {
Log.e("Your Array Response", response)
} else {
Log.e("Your Array Response", "Data Null")
}
}, Response.ErrorListener { error -> Log.e("error is ", "" + error) }) {
override fun getHeaders() : Map<String, String> {
val username ="admin"
val password = "admin"
val auth = "$username:$password"
var data = auth.toByteArray()
var base64 = Base64.encodeToString(data, Base64.NO_WRAP)
var headers = HashMap<String, String>()
headers.put("Authorization",base64)
headers.put("accept-language","EN")
headers.put("Content-type","application/json")
headers.put("Accept","application/json")
return headers
}
}
val queue = Volley.newRequestQueue(this)
queue.add(request)