LoginSignup
3
0

More than 3 years have passed since last update.

Volley に headers を付加する(Kotlin)

Posted at

Kotolin で Volley を使っていて、API アクセスの際に headers に認証情報を付加したかったので、やり方メモ

val queue = Volley.newRequestQueue(this)
val url = "アクセス先 URL"

val stringRequest = object: StringRequest(Request.Method.GET, url,
    Response.Listener{ response ->
        val toastText = response.toString()
        Toast.makeText(this, toastText, Toast.LENGTH_LONG).show()
    },
    Response.ErrorListener{
        // Error 処理
    })
{
    override fun getHeaders(): MutableMap<String, String> {
        val headers = HashMap<String, String>()
        headers["Authorization"] = "必要なアクセスキー情報"
        return headers
    }
}

queue.add(stringRequest)
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0