0

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)
  • this is very much dependent on the server you are calling you can debug in `BasicNetwork` the `performRequest` method and see what's being sent out – thepoosh Jul 24 '18 at 09:02
  • see post it implement basic authentication https://stackoverflow.com/questions/16817980/how-does-one-use-basic-authentication-with-volley-on-android – nyulan Jul 24 '18 at 09:04
  • thanks guys , the problem was in the server ... – Ahmed AbdulRahem Jul 25 '18 at 17:05

0 Answers0