Retrofit get post query filed FiledMap
2016-06-06 14:59
295 查看
直接请求型
1.如果是直接请求某一地址,写法如下:
@GET(“/record”)
Call getResult();
2.如果是组合后直接请求,如/result/{id}写法如下:
@GET(“/result/{id}”)
Call getResult(@Path(“id”) String id);
带参查询型
如12306的查询接口https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate=2016-03-18&from_station=BJP&to_station=CDW,写法如下:
@GET(“/otn/lcxxcx/query”)
Call query(@Query(“purpose_codes”) String codes, @Query(“queryDate”) String date,
@Query(“from_station”) String from, @Query(“to_station”) String to)
带Header型
比如要更新某个账户信息,其接口地址为/info,需要带的Header有设备信息device,系统版本version,还要带请求参数要更新账户的id,代码如下:
@POST(“/info”)
Call updateInfo(@Header(“device”) String device, @Header(“version”) int version,
@Field(“id”) String id);
HTTP请求方式:POST
请求示例为:
Request URL:http://api.duoshuo.com/posts/create.json
Request Method:POST
Post Data:short_name=official&author_email=jp.chenyang%40gmail.com&author_name=Perchouli&thread_id=1152923703638301959&author_url=http%3A%2F%2Fduoshuo.com&message=匿名发表新评论
1.Field方式实现
@FormUrlEncoded
@POST(“/posts/create.json”)
Call createCommit(@Field(“secret”) String secret,
@Field(“short_name”) String shortName,
@Field(“author_email”) String authorEmail,
@Field(“author_name”) String authorName,
@Field(“thread_key”) String threadKey,
@Field(“author_url”) String author_url,
@Field(“message”) String message);
2.Field Map实现方式
@FormUrlEncoded
@POST(“/posts/create.json”)
Call createCommit(@FieldMap Map
1.如果是直接请求某一地址,写法如下:
@GET(“/record”)
Call getResult();
2.如果是组合后直接请求,如/result/{id}写法如下:
@GET(“/result/{id}”)
Call getResult(@Path(“id”) String id);
带参查询型
如12306的查询接口https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate=2016-03-18&from_station=BJP&to_station=CDW,写法如下:
@GET(“/otn/lcxxcx/query”)
Call query(@Query(“purpose_codes”) String codes, @Query(“queryDate”) String date,
@Query(“from_station”) String from, @Query(“to_station”) String to)
带Header型
比如要更新某个账户信息,其接口地址为/info,需要带的Header有设备信息device,系统版本version,还要带请求参数要更新账户的id,代码如下:
@POST(“/info”)
Call updateInfo(@Header(“device”) String device, @Header(“version”) int version,
@Field(“id”) String id);
HTTP请求方式:POST
请求示例为:
Request URL:http://api.duoshuo.com/posts/create.json
Request Method:POST
Post Data:short_name=official&author_email=jp.chenyang%40gmail.com&author_name=Perchouli&thread_id=1152923703638301959&author_url=http%3A%2F%2Fduoshuo.com&message=匿名发表新评论
1.Field方式实现
@FormUrlEncoded
@POST(“/posts/create.json”)
Call createCommit(@Field(“secret”) String secret,
@Field(“short_name”) String shortName,
@Field(“author_email”) String authorEmail,
@Field(“author_name”) String authorName,
@Field(“thread_key”) String threadKey,
@Field(“author_url”) String author_url,
@Field(“message”) String message);
2.Field Map实现方式
@FormUrlEncoded
@POST(“/posts/create.json”)
Call createCommit(@FieldMap Map
相关文章推荐
- POJ 3625 Building Roads【MST】
- UIGestureRecognizer学习之UIPinchGestureRecognizer(捏合)
- 在Qt调用OpenCV库编写GUI程序
- easyUI Admin 模板
- UIButton之ImageEdgeInsets,TitleEdgeInsets详解
- IOS成长之路-UIButton定义和设置圆角
- LinearLayoutCompat源码浅析
- UIGestureRecognizer学习之UITapGestureRecognizer(点击)
- iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
- iOS学习4:UITextView的用法及技巧(ios7下光标bug解决方案)
- 20160606 DuiLib隐式链接(包含基本代码)
- UIGestureRecognizer学习之UIGestureRecognizer
- Easyui Datagrid相同连续列合并扩展(一)
- QtQuick 技巧 3
- 远程用户的WSDL访问问题以及SoapUI如何远程调用其他主机上的服务
- How to Build an High Availability MQTT Cluster for the Internet of Things
- 消息队列(Message Queue)简介及其使用
- 使用ShareUserId
- easy ui 如何从一个tab 跳转到另外一个tab
- Android UI设计之<十>自定义ListView,实现QQ空间阻尼下拉刷新和渐变菜单栏效果