【问题标题】:i'm not getting a response from volley我没有收到凌空的回应
【发布时间】:2021-09-09 18:34:31
【问题描述】:

我正在尝试构建一个天气应用程序,这是我第一次使用和 api 所以我从文档开始,但仍然没有得到回应

fun getWeather(view:View){
        val city = cityName.text.toString()
        cityName.text.clear()
        //val  url = "api.openweathermap.org/data/2.5/weather?q=$city&appid=cb8d284902f295b8759aa295cb6bafc3"
        val url = "https://www.google.com"
        val queue = Volley.newRequestQueue(this)
        val stringRequest = StringRequest(Request.Method.GET,url, Response.Listener<String> {
            response ->
            weatherResult.text = "it worked" + response.substring(0,10)
        },Response.ErrorListener {
            weatherResult.text = "there was an error"
        })
        queue.add(stringRequest)

    }

【问题讨论】:

  • 我必须使用“url”的值,因为我尝试了第一个,它给了我一个错误响应
  • 使用 printStackTrace() 查看错误并使用堆栈跟踪编辑您的问题。

标签: android android-studio kotlin android-volley android-api-levels


【解决方案1】:

我想应该是你的网址有问题。我注意到 api.openweathermap.org 中不包含 https:// 标头。

尝试添加 https://api.openweathermap.org/ 后跟您的搜索条件,它应该可以按预期工作。

【讨论】:

    猜你喜欢
    • 2017-12-31
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2016-11-20
    • 2012-10-25
    • 2018-11-01
    相关资源
    最近更新 更多