android - 我需要帮助才能发布到我的 api。我应该怎么办?
问题描述
我正在为我的应用程序创建登录名。我目前被困在向我的 API 发布问题
这是我用来支持登录的 API。
{
success: false,
message: "Please provide complete and accurate information.",
data: [ ]
}
fun loginUrlSuccess(urlApi : String) {
Log.d("login", urlApi)
authSignin_cgi = gson.fromJson(urlApi, DtoProfile::class.java)
loginsSuccess = authSignin_cgi.success
val queue = Volley.newRequestQueue(context)
val stringReq = object : StringRequest(Request.Method.POST,urlApi,Response.Listener<String>{ response ->
Log.w("response",response)
Toast.makeText(context,"Loging success..",Toast.LENGTH_SHORT).show()
if (loginsSuccess){
Toast.makeText(context,authSignin_cgi.message,Toast.LENGTH_LONG).show()
} else {
Toast.makeText(context,authSignin_cgi.message,Toast.LENGTH_LONG).show()
}
},Response.ErrorListener { error ->
Log.w("error", error.toString())
Toast.makeText(context, "error..$error",Toast.LENGTH_SHORT).show()
}){
override fun getParams(): MutableMap<String, String> {
val param = HashMap<String, String>()
val userEmail = textEmail.text.toString().trim()
val userPassword = textPassword.text.toString().trim()
param["useremail"] = userEmail
param["userpassword"] = userPassword
return param
}
}
queue.add(stringReq)
}
我从 Logcat 屏幕收到错误消息。
那我该怎么办?
04-04 15:31:43.614 8365-8699/com.example.atimeonlin5 E/Volley: [700] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL {"success":false,"message":"โปรดระบุข้อมูลให้ถูกต้องครบถ้วน","data":[]}
java.lang.RuntimeException: Bad URL {"success":false,"message":"โปรดระบุข้อมูลให้ถูกต้องครบถ้วน","data":[]}
解决方案
您应该使用 url(如"http://www.google.com"
),而不是随机字符串。你urlApi
不是网址。
来自文档的示例:
val textView = findViewById<TextView>(R.id.text)
// ...
// Instantiate the RequestQueue.
val queue = Volley.newRequestQueue(this)
val url = "http://www.google.com"
// Request a string response from the provided URL.
val stringRequest = StringRequest(Request.Method.GET, url,
Response.Listener<String> { response ->
// Display the first 500 characters of the response string.
textView.text = "Response is: ${response.substring(0, 500)}"
},
Response.ErrorListener { textView.text = "That didn't work!" })
// Add the request to the RequestQueue.
queue.add(stringRequest)
推荐阅读
- java - Spring Boot批处理 - 从计划任务运行多个批处理作业导致并发问题
- python - Python - Pandas - GroupBy 条件字符串加法
- python - 找到标准差最小值的组合
- javascript - 使用锚标签更新网址而不跳转到标签
- bash - 比较同一文件中的多个列
- ios - UITableViewCell 掩码选择区域/选择区域的大小?
- c - 在 C 中使用 goto 进行错误处理的奇怪行为
- cordova - 如何检查在 android 模拟器中为 ionic 生成的错误
- python - 将 python 对象从 python2 脚本传递到 python3 脚本
- python - 导入 Quandl 给出 ModuleNotFoundError: