Retrofit

        //    //http://  v.juhe.cn/   toutiao/index   ?type=top&key=097060266650f67b2cebd2a06aded587
//    //协议      ip地址+端口号  项目路径       请求参数
//    @GET("toutiao/index")
//    Call<XinWen> getNewsInfo(@Query("type")String leixing,@Query("key")String key);
//
//    @GET("toutiao/index")
//    Call<XinWen> getNewsInfo(@QueryMap Map<String,String> map);
//
//    @FormUrlEncoded//表单提交
//    @POST("toutiao/index")
//    Call<XinWen> getNewsInfo_Post(@Field("type") String type, @Field("key") String key);
//
//    @FormUrlEncoded//表单提交
//    @POST("toutiao/index")
//    Call<XinWen> getNewsInfo_Post(@FieldMap Map<String,String> map);


        Retrofit build = new Retrofit.Builder().baseUrl("http://v.juhe.cn/").addConverterFactory(GsonConverterFactory.create(new Gson())).build();
         Tou tou = build.create(Tou.class);
         //模式一
//       Call<XinWen> newsInfo = tou.getNewsInfo_Post("top", "f7c582ae70a71ac819c00f2d5b54ab48");
        //模式二
        HashMap<String, String> map = new HashMap<>();
        map.put("type","top");
        map.put("key","f7c582ae70a71ac819c00f2d5b54ab48");
        Call<XinWen> newsInfo = tou.getNewsInfo_Post(map);
        newsInfo.enqueue(new Callback<XinWen>() {
           @Override
           public void onResponse(Call<XinWen> call, Response<XinWen> response) {
               XinWen body = response.body();
               String title = body.getResult().getData().get(0).getTitle();
               Log.e("MainActivity", title);
           }


           @Override
           public void onFailure(Call<XinWen> call, Throwable t) {


           }
       });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值