首页 > 解决方案 > 我需要帮助才能发布到我的 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":[]}

标签: androidkotlingsonandroid-volley

解决方案


您应该使用 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)

推荐阅读