retrofit网络请求地址接口的拼接

添加依赖和网络权限
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
 
  
 
  
<uses-permission android:name="android.permission.INTERNET"/>

自定义接口
public interface weicy{
    //https://www.zhaoapi.cn/product/getProductDetail?pid=100&source=android
    @GET("/product/getProductDetail")
    Call get(@Query("pid") int pid, @Query("source") String source);
}
主页面
 
  
 
  
 
  
Retrofit retrofit =  new Retrofit.Builder().baseUrl("
 
  
 
  
https://www.zhaoapi.cn")
.addConverterFactory(GsonConverterFactory. create()) .build(); IGetDataBase iGetDataBase = retrofit.create(IGetDataBase. class); Call call = iGetDataBase.get( 4, "android"); call.enqueue( new Callback() { @Override public void onResponse(Call call, Response response) { Bean bean = response.body(); } @Override public void onFailure(Call call, Throwable t) { } });

你可能感兴趣的:(retrofit网络请求地址接口的拼接)