调用百度api微博热门精选接口,使用了volley,简单说说volley get的请求方式的使用

header的设置和请求参数的设置,见代码如下:

 private void getWeixinNews() {
StringBuilder sb = new StringBuilder();
try {
sb.append("?num=").append(10).append("&rand=").append(1).append("&word=").append((URLEncoder.encode("西游记","UTF-8")).toString()).
append("&page=").append(1).append("&src=").append((URLEncoder.encode("人民日报","UTF-8")).toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
stringRequest = new StringRequest(Request.Method.GET, "http://apis.baidu.com/txapi/weixin/wxhot"+sb.toString(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response);
parseJson(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Charset", "UTF-8");
headers.put("Content-Type", "application/x-javascript");
headers.put("Accept-Encoding", "gzip,deflate");
headers.put("apikey", "f8072b317a936623251258810df09d4e");
return headers;
} };
} private void parseJson(String response) {
Gson gson = new Gson();
BigWeiXin bigWeiXin = gson.fromJson(response, BigWeiXin.class);
List<WeiXin> newslist = bigWeiXin.getNewslist();
for (WeiXin weixin : newslist) {
Log.d("TAG", "ctime is " + weixin.getCtime());
Log.d("TAG", "title is " + weixin.getTitle());
Log.d("TAG", "description is " + weixin.getDescription());
Log.d("TAG", "picUrl is " + weixin.getPicUrl());
Log.d("TAG", "url is " + weixin.getUrl());
}
}

  

android volley get请求使用的更多相关文章

  1. android volley http请求框架

    2015年11月6日 14:35:19 注意: 1.安卓官方的volley在google的codesource上, 在github上有他的镜像android-volley, 并解决了官方的一部分bug ...

  2. 基于Android Volley的网络请求工具

    基于Android Volley的网络请求工具. 一.说明 AndroidVolley,Android Volley核心库及扩展工程.AndroidVolleySample,网络请求工具示例工程.Re ...

  3. 035 Android Volley框架进行网络请求

    1.volley入门介绍 开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行HTTP通 ...

  4. Android okHttp网络请求之Get/Post请求

    前言: 之前项目中一直使用的Xutils开源框架,从xutils 2.1.5版本使用到最近的xutils 3.0,使用起来也是蛮方便的,只不过最近想着完善一下app中使用的开源框架,由于Xutils里 ...

  5. [Android]Volley源码分析(一)

    一. 如何使用Volley? 1. 首先定义一个RequestManager类,用来在Android程序启动时对Volley进行初始化.RequestManager为单例类,因为只有在程序启动时调用, ...

  6. [Android]Volley的使用

    Volley是Google I/O 2013上提出来的为Android提供简单快速网络访问的项目.Volley特别适合数据量不大但是通信频繁的场景. 优势 相比其他网络载入类库,Volley 的优势官 ...

  7. [转] Android Volley完全解析(一),初识Volley的基本用法

    版权声明:本文出自郭霖的博客,转载必须注明出处.   目录(?)[-] Volley简介 下载Volley StringRequest的用法 JsonRequest的用法   转载请注明出处:http ...

  8. Android Volley入门到精通:定制自己的Request

    经过前面两篇文章的学习,我们已经掌握了Volley各种Request的使用方法,包括StringRequest.JsonRequest.ImageRequest等.其中StringRequest用于请 ...

  9. Android Volley入门到精通:使用Volley加载网络图片

    在上一篇文章中,我们了解了Volley到底是什么,以及它的基本用法.本篇文章中我们即将学习关于Volley更加高级的用法,如何你还没有看过我的上一篇文章的话,建议先去阅读Android Volley完 ...

随机推荐

  1. dict和set

    #dict和set #dict #Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map #使用键-值(key-value)存储,具有极快的查找速度. #字 ...

  2. Android logcat

    logcat是Android中一个命令行工具,可以用于得到程序的log信息. 基本命令 logcat使用方法如下所示: [adb] logcat [<option>] ... [<f ...

  3. iOS 正则表达式判断邮箱、身份证..是否正确

    //邮箱 + (BOOL) validateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Z ...

  4. 捡火柴的Nova君(n个线段相交问题)

    题目来源:https://biancheng.love/contest-ng/index.html#/41/problems 捡火柴的Nova君 题目描述 南方没暖气,怕冷的的宝宝们只能用火柴取暖.然 ...

  5. [windows]利用IPSec对指定的ip进行访问限制

    以win2003系统为例: 操作(看图): 1.任务:现在192.168.2.200可访问;目的;本地禁止对其访问 2.进入:管理工具->本地安全设置->IP安全策略 3.右键创建IP安全 ...

  6. keepalived初探

    keepalived起初是为LVS设计的,专门用来监控LVS集群系统中各个real server的健康状况的,后来又在其中实现了VRRP协议,VRRP即virtual router redundanc ...

  7. 【linux】关于TCP三次握手和四次挥手

    1.TCP是什么 关于OSI的七层模型 TCP在第四层——Transport层,第四层的数据叫Segment->报文 IP在第三层——Network层,在第三层上的数据叫Packet->数 ...

  8. sqlserver2008链接服务器的使用和oracle11g客户端修改字符集

    1.服务器对象-链接服务器-访问接口-(OracleDB.Oracle)属性-允许进程内 2.运行-regedit-HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE-NIS_LAN ...

  9. jsp中的四种对象作用域

    page:当前页面,也就是只要挑到别的页面就失效了,可以近似理解为java的this对象 request:一次会话,简单的理解就是一次请求范围内有效,例如如果通过forward方式跳转,则forwar ...

  10. spring 容器加载完成后执行某个方法

    理论 刚好再开发过程中遇到了要在项目启动后自动开启某个服务,由于使用了spring,我在使用了spring的listener,它有onApplicationEvent()方法,在Spring容器将所有 ...