【问题标题】:I need help for post to my api. What should I do?我需要帮助才能发布到我的 api。我该怎么办?
【发布时间】:2019-08-25 22:50:35
【问题描述】:

我正在为我的应用程序创建一个登录名。 我目前被困在向我的 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":[]}

【问题讨论】:

    标签: android kotlin gson android-volley


    【解决方案1】:

    您应该使用 url(如 "http://www.google.com"),而不是随机字符串。您的urlApi 不是网址。

    来自doc的示例:

    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)
    

    【讨论】:

      【解决方案2】:

      好吧,你应该尝试构造一个 Url 对象而不是 String 类型!

      【讨论】:

        猜你喜欢
        • 2013-12-24
        • 2012-01-18
        • 2013-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-12
        相关资源
        最近更新 更多