这是错误的截图
这是我的代码,用来过滤数据
private fun fetchdata() {
val queue = Volley.newRequestQueue(this)
val url =
"http://newsapi.org/v2/everything?domains=wsj.com&apiKey=APIKEY"
val jsonObjectRequest = JsonObjectRequest(
Request.Method.GET, url, null,
{
val newsJSONArray = it.getJSONArray("articles")
val newsArray = ArrayList<News>()
for (i in 0 until newsJSONArray.length()) {
val newsJSONObject = newsJSONArray.getJSONObject(i)
val news = News(
newsJSONObject.getString("author"),
newsJSONObject.getString("title"),
newsJSONObject.getString("description"),
newsJSONObject.getString("urlToImage")
)
newsArray.add(news)
}
mAdapter(this, newsArray)
}, {
})
fun getHeaders():MutableMap<String,String>{
val headers=HashMap<String,String>()
headers["Content-type"]
return headers
}
}
我犯了个错误
11-13 19:31:13.104 4688-4709/com.example.volley_demo E/Volley: [254] BasicNetwork.performRequest: Unexpected response code 403 for http://newsapi.org/v2/everything?domains=wsj.com&apiKey=APIKEY
11-13 19:31:14.929 4688-4709/com.example.volley_demo D/Volley: [254] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://newsapi.org/v2/everything?domains=wsj.com&apiKey=APIKEY 0xc16ea6dd NORMAL 1> [lifetime=4644], [size=11258], [rc=403], [retryCount=1]
11-13 19:31:14.930 4688-4709/com.example.volley_demo E/Volley: [254] BasicNetwork.performRequest: Unexpected response code 403 for http://newsapi.org/v2/everything?domains=wsj.com&apiKey=APIKEY
1条答案
按热度按时间fnx2tebb1#
检查你的url方法它真的得到了吗?尝试使用post检查。提出请求时还要检查您的互联网连接。