- 第一步:权限和依赖
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- **上传头像的接口传参 POST类型 SmallServer 接口 **
@Multipart
@POST(MyApi.SHANGCHUANTOUXIANG_URL)
Observable<ShangChuanTouxiangBean> getShangChuan(@Part MultipartBody.Part file);
- 网络工具类调用(上)Base拼接
public class RetrofitHttp {
SmallServer smallServer;
private RetrofitHttp(){
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HouTou())
.addInterceptor(loggingInterceptor)
.build();
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(MyApi.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
smallServer = retrofit.create(SmallServer.class);
}
private static final class Retr{
static RetrofitHttp retrofitHttp = new RetrofitHttp();
}
public static RetrofitHttp getInstance(){
return Retr.retrofitHttp;
}
}
public void getShan(File image, Observer<ShangChuanTouxiangBean> observer