大佬教程收集整理的这篇文章主要介绍了BasicNetwork.performRequest:带有 Volley 库的 newsapi.org 的意外响应代码 403,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这里有一个简单的代码来返回任何数据,API 网站有 JsON 对象文件。我尝试了很多不同的东西仍然不起作用。然而,它完美地工作,让我们说https://www.metaweather.com/api/。我导入了库和互联网权限,当我吐槽错误时,它说 Volley.AuthFailure。任何帮助将不胜感激谢谢
getBtn.setonClickListener(new VIEw.onClickListener() {
@OverrIDe
public voID onClick(View view) {
requestQueue requestQueue;
// Instantiate the cache
Cache cache = new diskBasedCache(getCacheDir(),1024 * 1024); // 1MB cap
// Set up the network to use httpURLConnection as the http clIEnt.
Network network = new BasicNetwork(new HurlStack());
// Instantiate the requestQueue with the cache and network.
requestQueue = new requestQueue(cache,network);
// Start the queue
requestQueue.start();
String url ="https://newsAPI.org/v2/top-headlines?country=us&APIKey=ba4529c51872486fb59a7a98de934d54";
// Formulate the request and handle the response.
Stringrequest Stringrequest = new Stringrequest(request.Method.GET,url,new Response.Listener<String>() {
@OverrIDe
public voID onResponse(String responsE) {
// Do something with the response
Toast.makeText(MainActivity.this,"YAHOOOOO success!",Toast.LENGTH_SHORT).show();
}
},new Response.ErrorListener() {
@OverrIDe
public voID onErrorResponse(VolleyError error) {
// Handle error
Toast.makeText(MainActivity.this,"Error occurred" + error,Toast.LENGTH_SHORT).show();
}
});
// Add the request to the requestQueue.
requestQueue.add(Stringrequest);
}
});
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的BasicNetwork.performRequest:带有 Volley 库的 newsapi.org 的意外响应代码 403全部内容,希望文章能够帮你解决BasicNetwork.performRequest:带有 Volley 库的 newsapi.org 的意外响应代码 403所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。