Android python中与Kotlin等效的request.post()是什么?
因此,我试图使用一个网站的API,但为了使用它,我必须发送我的登录信息。文档向我展示了一个关于如何登录的python示例Android python中与Kotlin等效的request.post()是什么?,android,kotlin,android-volley,Android,Kotlin,Android Volley,因此,我试图使用一个网站的API,但为了使用它,我必须发送我的登录信息。文档向我展示了一个关于如何登录的python示例 R = requests.post('http://nova.astrometry.net/api/login', data={'request-json': json.dumps({"apikey": "XXXXXXXX"})}) print(R.text) 那么Kotlin与上述代码的等价物是什么?在网站文档中,它指出 “注意r
R = requests.post('http://nova.astrometry.net/api/login', data={'request-json':
json.dumps({"apikey": "XXXXXXXX"})})
print(R.text)
那么Kotlin与上述代码的等价物是什么?在网站文档中,它指出
“注意request json=VALUE:我们不是发送原始json,而是发送json编码的字符串,就像它是一个名为request json的文本字段一样。”
我尝试过使用,但我不完全确定如何使用它
private fun plateSolve(){
val json=JSONObject(map).toString()
Log.d(TAG,"URL:$url")
Log.d(TAG,"Hashmap:$json")
JSONObject(map).toString()
val jsonObjectRequest = JsonObjectRequest(
Request.Method.POST, url, null,
{ response ->
try {
Log.d(TAG,"POST Response: %s".format(response.toString()))
}catch (e:Exception){
Log.d(TAG,"Exception: $e")
}
},
{ error ->
// TODO: Handle error
Log.d(TAG,"There Was an Error")
error.stackTraceToString()
}
)
// Access the RequestQueue through your singleton class.
VolleySingleton.instance?.addToRequestQueue(jsonObjectRequest)
}
提前感谢不建议在android上再使用volley,请使用改型作为谷歌的推荐库,你的问题的答案太大了,所以我会写一些检查点来做,并且我在github上分享了一个简单的改型工作示例,希望这对你有所帮助 改装连接-