zoukankan      html  css  js  c++  java
  • Retrofit最基本用法

    package qianxingzhe.retrofit_learning;
    
    import java.util.List;
    import java.util.Map;
    
    import retrofit2.Call;
    import retrofit2.http.Body;
    import retrofit2.http.Field;
    import retrofit2.http.FieldMap;
    import retrofit2.http.FormUrlEncoded;
    import retrofit2.http.GET;
    import retrofit2.http.POST;
    import retrofit2.http.Path;
    import retrofit2.http.Query;
    import retrofit2.http.QueryMap;
    
    /**
     * Created by lunyi.yly on 16/8/7.
     */
    
    public interface GitHubService {
        @GET("repos/{owner}/{repo}/contributors")
        Call<List<Contributor>> listContributor(@Path("owner") String owner, @Path("repo") String repo);
    
        /**
         * 一个简单的get请求。如: http://102.10.10.132/api/News
         *
         * @return
         */
        @GET("News")
        Call<String> get_01();
    
        /**
         * URL中有参数。如: http://102.10.10.132/api/News/1
         *
         * @param newsId
         * @return
         */
        @GET("News/{newsId}")
        Call<String> get_02(@Path("newsId") String newsId);
    
        /**
         * 参数在URL问号之后。如: http://102.10.10.132/api/News?newsId=1
         *
         * @param newsId
         * @return
         */
        @GET("News")
        Call<String> get_03(@Query("newsId") String newsId);
    
        /**
         * 多个参数在URL问号之后,且个数不确定。如: http://102.10.10.132/api/News?newsId=1&type=类型1...
         *
         * @param map
         * @return
         */
        @GET("News")
        Call<String> get_04(@QueryMap Map<String, String> map);
    
        /**
         * 需要补全URL,post的数据只有一条reason。如: http://102.10.10.132/api/Comments/1
         *
         * @param newsId
         * @param reason
         * @return
         */
        @FormUrlEncoded
        @POST("Comments/{newsId}")
        Call<String> post_01(@Path("newsId") String newsId, @Field("reason") String reason);
    
        /**
         * 需要补全URL,问号后加入access_token,post的数据只有一条reason。如:http://102.10.10.132/api/Comments/1?access_token=1234123
         *
         * @param newsId
         * @param access_token
         * @param reason
         * @return
         */
        @FormUrlEncoded
        @POST("Comments/{newsId}")
        Call<String> post_02(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @Field("reason") String reason);
    
        /**
         * 需要补全URL,问号后加入access_token,post的数据有多条。如:http://102.10.10.132/api/Comments/1?access_token=1234123
         *
         * @param newsId
         * @param access_token
         * @return
         */
        @FormUrlEncoded
        @POST("Comments/{newsId}")
        Call<String> post_03(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @FieldMap Map<String, String> map);
    
        /**
         * 需要补全URL,问号后加入access_token,post一个body(对象)。如:http://102.10.10.132/api/Comments/1?access_token=1234123
         *
         * @param newsId
         * @param access_token
         * @param contributor
         * @return
         */
        @FormUrlEncoded
        @POST("Comments/{newsId}")
        Call<String> post_04(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @Body Contributor contributor);
    }
    
    
  • 相关阅读:
    云谷分布式端口扫描与代理验证系统(一)简介
    Linux 共享库:LD_LIBRARY_PATH 与ld.so.conf_爱过了就好_新浪博客
    分享:QT QJson库编译心得
    分享:Zed Attack Proxy 2.0 发布,Web 渗透测试
    LIBTOOL is undefined 解决方法
    linux下.a/.so/.la目标库区别
    LDAmath文本建模
    分享:SchemaCrawler 9.4 发布,数据库结构输出
    JQ也要面向对象~在JQ中扩展静态方法和实例方法
    将不确定变为确定~Flag特性的枚举是否可以得到Description信息
  • 原文地址:https://www.cnblogs.com/FlySheep/p/5746153.html
Copyright © 2011-2022 走看看