无法使用Volley向Monzo的API进行身份验证 [英] Can't authenticate with Monzo's API using Volley
问题描述
我正在尝试从Monzo获取身份验证令牌,如文档. 当我从终端使用httpie发出请求时,我没有问题,但是当我使用Volley发出请求时,得到了400响应. 我确认使用 https://postman-echo.com/post正确使用了Volley. a>端点.
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.
以下对Volley的使用是否明智?
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
}
}
推荐答案
该API似乎不支持application/json,在邮递员中做了一些工作.该请求的格式应为application/x-www-form-urlencoded.
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.
这篇关于无法使用Volley向Monzo的API进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!