Can't authenticate with Monzo's API using Volley

前提是你 提交于 2019-12-13 03:59:43

问题


I'm trying to get the authentication token from Monzo as in the section 'Exchange the authorization code' in the docs. When I make the request using httpie from the terminal I have no problem, but when I make the request using Volley I get a 400 response. I've confirmed that I'm using Volley correctly using the https://postman-echo.com/post endpoint.

Does the following use of Volley look sensible?

VolleyLog.DEBUG = true;
val jsonBody = JSONObject()

jsonBody.put("grant_type", "authorization_code")
jsonBody.put("client_id", "oauth2client_somestring")
jsonBody.put("client_secret", "mnzpub.somestring/somestring")
jsonBody.put("redirect_uri", "http://www.sample.com")
jsonBody.put("code", code)

val request = object : JsonObjectRequest(
    Method.POST, "https://api.monzo.com/oauth2/token", jsonBody,
    Response.Listener<JSONObject> {
        println("Got some response")
    },
    Response.ErrorListener {
        println("That didn't work!") }) {
    override fun getHeaders(): Map<String, String> {
        val params = HashMap<String, String>()
        params["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8"
        return params
    }
}

回答1:


It looks like the API doesn't support application/json, having done a bit of playing about in postman. The request should be formatted as application/x-www-form-urlencoded.



来源:https://stackoverflow.com/questions/57149422/cant-authenticate-with-monzos-api-using-volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!