精华内容
下载资源
问答
  • Android Retrofit 中文乱码问题的解决办法使用retrofit和rxjava,提交数据时需注意,当数据中有中文时,传到后台,可能会是乱码,需处理:解决:1.GET请求改成POST;2.参数Field改成Query3.加上@FormUrlEncoded如下:...

    Android Retrofit 中文乱码问题的解决办法

    使用retrofit和rxjava,提交数据时需注意,当数据中有中文时,传到后台,可能会是乱码,需处理:

    解决:

    1.GET请求改成POST;

    2.参数Field改成Query

    3.加上@FormUrlEncoded

    如下:

    @FormUrlEncoded

    @POST("/test/test")

    Call register(@Field("name") String name);

    @FormUrlEncoded

    @POST("/test/test")

    Call someEndpoint(@FieldMap Map names);

    解决例子:

    如此写上报后台会有乱码:(若name和remark有中文)

    //支付订单

    @GET("app/shopcart/pay")

    Observable payOrder(

    @Query("token") String token, @Query("shopcartIdArray") String[] shopcartIdArray, @Query("name") String name, @Query("remake") String remake

    );

    修改为:

    //支付订单

    @FormUrlEncoded

    @POST("app/shopcart/pay")

    Observable payOrder(

    @Field("token") String token, @Field("shopcartIdArray") String[] shopcartIdArray,@Field("name") String name, @Field("remake") String remake

    );

    如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

    展开全文
  • The previous app process crashed. This is the stack trace of the crash: java.lang.IllegalArgumentException... for method ApiService.deleteBank1 @DELETE("api/user/fund/bank-account") fun deleteBan...

    The previous app process crashed. This is the stack trace of the crash:
        java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.
            for method ApiService.deleteBank1

      @DELETE("api/user/xxx")
        fun deleteBank1(
            @Body params: RequestBody
        ): Observable<BaseResponse<Any>>

    刚开始delete请求按Post进行了上面配置,但请求接口时就崩溃报上面错误了:  Non-body HTTP method cannot contain @Body

    然后改为如下形式

    @DELETE("api/user/xxx")
    fun deleteBank(
        @Query("uid") uid: String,
        @Query("number") number: String
    ): Observable<BaseResponse<Any>>

    结果服务端又返回 {"code":400,"msg":"EOF"},问服务端小弟说是Body形式,但第一种就是Body封装请求了,难道还有其他方式,查询了一下才发现还需要额外配置body.

     @HTTP(method = "DELETE", path = "api/user/xxx", hasBody = true)
        fun deleteBank(
            @Body params: RequestBody
        ): Observable<BaseResponse<Any>>

    如上面方式  hasBody 设置为true后再请求就正常了

    上面是一种Delete的形式,还有可能只有value而不是key-value形式,如 api/user/xxx/{id},则通过@Path进行配置

        @HTTP(method = "DELETE", path = "api/user/xxx/{id}", hasBody = true)
        Observable<BaseResponse> schoolDeletePic(@Path("id") String id);

    展开全文
  • ApiService 中的写法:@POST("/upload/xxx")fun xxxMethod(@Body body: RequestBody): ObservablePS: 之前有印象好像可以通过 @Part 注解来一起上传,后来项目中又不好使了,不知道哪里的问题。...

    ApiService 中的写法:

    @POST("/upload/xxx")

    fun xxxMethod(

    @Body body: RequestBody

    ): Observable

    PS: 之前有印象好像可以通过 @Part 注解来一起上传,后来项目中又不好使了,不知道哪里的问题。

    上面接口中传递的是 Body 格式,下面来看一下生成 body 的方法:

    fun generateUploadBody(file: File, fileKey: String, keyValues: HashMap.() -> Unit = {}): RequestBody {

    val body = RequestBody.create(MediaType.parse("multipart/form-data"), file)

    // EncodeUtil.urlEncodeUtf8 这里是为了避免中文文件名引起的乱码问题。

    val part= MultipartBody.Part.createFormData(fileKey, EncodeUtil.urlEncodeUtf8(file.name), body)

    val params = HashMap().apply(keyValues)

    val mulBody = MultipartBody.Builder().apply {

    addPart(part)

    params.map {

    addFormDataPart(it.key, it.value)

    }

    }.build()

    return mulBody

    }

    注意:fileKey 也就是服务端用来接收这个文件的 Key . 就跟我们传递普通参数的 Key 是一个意思。

    下面是用法:

    val body = HttpUtil.generateUploadBody(file, "photo") {

    // 这里是给 Map 添加值

    put("userName", userName)

    ...

    }

    .... 把 body 传给接口。

    这里都是以 Kotlin 语法写的,如有需要,自行调整 Java 语法

    展开全文
  • 1、build.gradle添加依赖 //jetpack组件库 api 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0' api 'androidx.lifecycle:lifecycle-... //retrofit网络请求和okhttp网络请求 api "com.squareup.okhtt

    1、build.gradle添加依赖

        //jetpack组件库
        api 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
        api 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    
        api "com.google.code.gson:gson:2.8.5"
    
        //retrofit网络请求 、 okhttp网络请求和Rxjava3
        api "com.squareup.okhttp3:logging-interceptor:4.7.2"
        api "com.squareup.retrofit2:converter-gson:2.9.0"
        api "com.squareup.retrofit2:retrofit:2.9.0"
        api "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
    
        //glide图片加载
        api 'com.github.bumptech.glide:glide:4.12.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
    
        //RxAndroid RxLifecycle是为了防止RxJava中subscription导致内存泄漏而诞生的,核心思想是通过监听Activity、Fragment的生命周期,来自动断开subscription以防止内存泄漏
        api 'com.trello.rxlifecycle4:rxlifecycle:4.0.2'
        api 'com.trello.rxlifecycle4:rxlifecycle-components:4.0.2'
        api 'com.trello.rxlifecycle4:rxlifecycle-android:4.0.2'
    
        api 'com.alibaba:arouter-api:1.5.1'

    2、新建BaseActivity、BaseFragment   以防止内存泄漏  继承RxAppCompatActivity和RxFragment

    public class BaseActivity extends RxAppCompatActivity {
    }
    
    
    public class BaseFragment extends RxFragment {
    }

    3、Application增加registerActivityLifecycleCallbacks  可以监听到 Activity 的状态,从而可以判断 APP 是否在前台或者后台等

    public class EnterApplication extends Application {
    
        @Override
        protected void attachBaseContext(Context base) {
            AppGlobalVar.appContext = base;
            AppGlobalVar.currentLanguage = LanguageHandler.getInstance().getLanguage();
            super.attachBaseContext(LanguageHandler.getInstance().setLocal(base));
        }
    
        @Override
        public void onCreate() {
            super.onCreate();
    
            CrashHandler.getInstance().init(this);
    
            //路由初始化
            if (AppGlobalVar.isDebug) {
                ARouter.openLog();
                ARouter.openDebug();
            }
    
            ARouter.init(this);
    
            int myPid = android.os.Process.myPid();
    
            DataStoreManager.init(this);
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                String processName = AppUtils.getProcessName(this, myPid);
                if (!BuildConfig.APPLICATION_ID.equals(processName)) {
                    String processEndSuffix = StringUtils.getProcessEndfix(processName);
                    if (TextUtils.isEmpty(processEndSuffix)) {
                        processEndSuffix = "other";
                    }
                    WebView.setDataDirectorySuffix(processEndSuffix);
                }
            }
    
            registerActivityLifecycleCallbacks(new AppActivityLifecycleCallbacks());
    
        }
    }
    
    
    
    public class AppActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
    
        @Override
        public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
            ActivityStackManager.add(activity);
        }
    
        @Override
        public void onActivityStarted(@NonNull Activity activity) {
    
        }
    
        @Override
        public void onActivityResumed(@NonNull Activity activity) {
            isAppBackground = false;//app回到前台
        }
    
        @Override
        public void onActivityPaused(@NonNull Activity activity) {
    
        }
    
        @Override
        public void onActivityStopped(@NonNull Activity activity) {
            isAppBackground = true;//app在后台
        }
    
        @Override
        public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
    
        }
    
        @Override
        public void onActivityDestroyed(@NonNull Activity activity) {
            ActivityStackManager.remove(activity);
        }
    }

    4、网络请求类  采用Retrofit网络请求

    public class NetworkManager {
    
        private static String DEFAULT_BASE_URL = "http://api.xx.retrofit.com/";
    
        private CommonInterceptor commonInterceptor;
    
        private static final Map<String, Retrofit> retrofitMap = new HashMap<>();
    
        private CookieJar cookieJar;
    
        private static NetworkManager instance;
    
        private NetworkManager() {
        }
    
        public static NetworkManager getInstance() {
            if (instance == null) {
                instance = new NetworkManager();
            }
            return instance;
        }
    
        public void setDefaultDomain(String domain) {
            if (!TextUtils.isEmpty(domain)) {
                if (!domain.endsWith("/")) {
                    domain += "/";
                }
                DEFAULT_BASE_URL = domain;
            }
        }
    
        public String getDefaultDomain() {
            return DEFAULT_BASE_URL;
        }
    
        public void setCommonParams(Map<String, String> commonParams) {
            commonInterceptor = new CommonInterceptor(commonParams);
        }
    
        public void setCookieJar(CookieJar cookieJar) {
            this.cookieJar = cookieJar;
        }
    
        private Retrofit buildRetrofit() {
            return buildRetrofit(DEFAULT_BASE_URL);
        }
    
        private Retrofit buildRetrofit(String baseUrl) {
    
            Retrofit retrofit;
            if (retrofitMap.containsKey(baseUrl)) {
                retrofit = retrofitMap.get(baseUrl);
            } else {
    
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
                HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
                loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                builder.addInterceptor(loggingInterceptor);
    
                if (commonInterceptor != null) {
                    builder.addInterceptor(commonInterceptor);
                }
    
                if (cookieJar != null) {
                    builder.cookieJar(cookieJar);
                }
    
                OkHttpClient okHttpClient = builder
                        .readTimeout(10, TimeUnit.SECONDS)
                        .connectTimeout(10, TimeUnit.SECONDS)
                        .retryOnConnectionFailure(true)
                        .build();
                retrofit = new Retrofit.Builder()
                        .baseUrl(baseUrl)
                        .client(okHttpClient)
                        .addConverterFactory(CustomGsonConverterFactory.create())
                        .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                        .build();
    
                retrofitMap.put(baseUrl, retrofit);
            }
    
            return retrofit;
        }
    
        public <T> T create(final Class<T> service) {
            return buildRetrofit().create(service);
        }
    
        public <T> T create(String baseUrl, final Class<T> service) {
            return buildRetrofit(baseUrl).create(service);
        }
    
    }

    5、网络请求interface 

    public interface ListService {
    
        @GET("/Product/List")
        Observable<BaseResponse<ListCard>> getActList(@QueryMap Map<String, String> paramsMap);
    
    }
    
    //@GET("/Product/List") 接口名 
    //ListCard实体类 可以通过RoboPOJOGenerator插件生成
    //@QueryMap Map<String, String> paramsMap  是传入map参数
    //如果传入string参数 可以这样写@Query("item_id") String item_id,@Query("page") int page
    
    
    
    
    public class  ListCard {
    
    	@SerializedName("image")
    	public String image;
    
    	@SerializedName("currPage")
    	public Integer currPage;
    
    	@SerializedName("pageTotal")
    	public Integer pageTotal;
    
    	@SerializedName("prePage")
    	public Integer prePage;
    
    	@SerializedName("list")
    	public List<ProductCard> list;
    
    	@SerializedName("title")
    	public  String title;
    
    	@SerializedName("desc")
    	public  String desc;
    }
    

    6、创建ViewModel+LiveData

    public class ListViewModel extends ViewModel {
    
        private ListService listService;
        private final SingleLiveData<ListCard> listData = new SingleLiveData<>();
        public MutableLiveData<Integer> listError = new MutableLiveData<>();
    
    
        public MutableLiveData<ListCard> getActListData(Context context, Map<String, String> paramsMap){
    
            if (listService == null) {
                listService = NetworkManager.getInstance().create(ListService.class);
            }
            listService.getActList(paramsMap)
                    .compose(RxJavaHelper.observableIO2Main(context))
                    .subscribe(new BaseObserver<ListCard>() {
                        @Override
                        public void onSuccess(ListCard result) {
                            listData.postValue(result);
                        }
    
                        @Override
                        public void onFailure(NetworkException e) {
                            listError.postValue(-1);
                        }
                    });
    
            return listData;
        }
    }
    
    //因为数据需要分页加载  用SingleLiveData
    
    public class SingleLiveData<T> extends MutableLiveData<T> {
    
        private final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
    
        @Override
        public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer<? super T> observer) {
            super.observe(owner, t -> {
                if (atomicBoolean.compareAndSet(true, false)) {
                    observer.onChanged(t);
                }
            });
        }
    
        @Override
        public void postValue(T value) {
            atomicBoolean.set(true);
            super.postValue(value);
        }
    
    }
    
    
    
    
    public class RxJavaHelper {
    
        public static <T> ObservableTransformer<T, T> observableIO2Main(final Context context) {
            return upstream -> {
                Observable<T> observable = upstream.subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread());
                return composeContext(context, observable);
            };
        }
    
        public static <T> ObservableTransformer<T, T> observableIO2Main(final RxFragment fragment) {
            return upstream -> upstream.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread()).compose(fragment.<T>bindToLifecycle());
        }
    
        public static <T> FlowableTransformer<T, T> flowableIO2Main() {
            return upstream -> upstream
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread());
        }
    
        private static <T> ObservableSource<T> composeContext(Context context, Observable<T> observable) {
            if (context instanceof RxActivity) {
                return observable.compose(((RxActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
            } else if (context instanceof RxFragmentActivity) {
                return observable.compose(((RxFragmentActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
            } else if (context instanceof RxAppCompatActivity) {
                return observable.compose(((RxAppCompatActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
            } else {
                return observable;
            }
        }
    
    }
    
    
    /**
    用于这种网络结构
    
    {
    	"code": "40000",
    	"action": "",
    	"message": "hhhh",
    	"data": {}
    }
    */
    
    
    public class BaseResponse<T> {
    
        public int code;
        public String message;
        public String action;
        public T data;
    }
    
    
    
    public abstract class BaseObserver<T> implements Observer<BaseResponse<T>> {
    
        private final String TAG = "BaseObserver";
    
        public static final String ACTION_TOAST = "toast";
    
        @Override
        public void onSubscribe(@NonNull Disposable d) {
            LogUtils.i(TAG, "onSubscribe");
        }
    
        @Override
        public void onNext(@NonNull BaseResponse<T> baseResponse) {
    
            LogUtils.i(TAG, "onNext: message = %s ; code = %d", baseResponse.message, baseResponse.code);
            if (baseResponse.code == 0) {
                if (baseResponse.data == null) {
                    LogUtils.e(TAG, "onNext: data is null");
                    onFailure(new NetworkException(baseResponse.action, "data is null", NetworkException.CODE_DATA_NULL));
                } else {
                    onSuccess(baseResponse.data);
                }
            } else {
                onFailure(new NetworkException(baseResponse.action, baseResponse.message, baseResponse.code));
            }
    
            onAction(baseResponse.action, baseResponse.message);
        }
    
        @Override
        public void onError(@NonNull Throwable e) {
            String errorMsg = NetworkError.handler(e);
            LogUtils.e(TAG, "onError: %s ; code = %d", errorMsg, NetworkException.CODE_ERROR);
            onFailure(new NetworkException("", errorMsg, -1));
        }
    
        @Override
        public void onComplete() {
            LogUtils.i(TAG, "onComplete");
        }
    
        public abstract void onSuccess(T result);
    
        public abstract void onFailure(NetworkException e);
    
        public boolean isToast(String action) {
            return TextUtils.equals(action, ACTION_TOAST);
        }
    
        protected void onAction(String action, String message) {
            if (isShowToast()) {
                showToast(action, message);
            }
        }
    
        /**
         * 是否显示toast ,默认不弹
         */
        protected boolean isShowToast() {
            return false;
        }
    
        private void showToast(String action, String message) {
            if (isToast(action)) {
                ToastUtils.showCenterToast(message);
            }
        }
    
    }
    
    
    
    
    public class NetworkException extends Exception {
    
        public static final int CODE_DATA_NULL = 80000; // 空数据
        public static final int CODE_ERROR = -99999;// 异常
    
        private String action;
    
        private String message;
    
        private final int errorCode;
    
        public int getErrorCode() {
            return errorCode;
        }
    
        public String getAction() {
            return action;
        }
    
        public String getMessage() {
            return message;
        }
    
        public NetworkException(String action, String message, int errorCode) {
            super(message);
            this.action = action;
            this.errorCode = errorCode;
            this.message = message;
        }
    }

    7、Activity请求接口

    @Route(path = RoutePath.APP_ACT_LIST)
    public class ListActivity extends BaseActivity {
        private String LOG_TAG = "ListActivity";
        private ActivityActListBinding binding;
        private int currPage = 1;
        private ListViewModel listViewModel;
        private ActListAdapter actListAdapter;
        private Map<String, String> paramsMap;
    
    
        @Override
        public View getBindingView() {
            binding = ActivityActListBinding.inflate(getLayoutInflater());
            return binding.getRoot();
        }
    
        @Override
        public void initPage() {
            StatusBarUtil.immersiveTitleView(binding.actHeadLayout);
            binding.rvActList.setLayoutManager(new LinearLayoutManager(this));
            binding.rvActList.addItemDecoration(new ActSpacesItemDecoration(this));
            paramsMap = getIntentParams();
            actListAdapter = new ActListAdapter(this);
            binding.rvActList.setAdapter(actListAdapter);
            actListViewModel = new ViewModelProvider(this).get(ListViewModel.class);
            requestActList(1);
            actListViewModel.actListError.observe(this, integer -> {
                //update ui
                LogUtils.e(LOG_TAG, "请求出错");
    
            });
            binding.actBack.setOnClickListener(view -> finish());
            binding.rvActList.setLoadMoreListener(() -> {
                currPage++;
                requestActList(currPage);
            });
        }
    
    
        private void requestActList(int page) {
            paramsMap.put("page",page+"");
            actListViewModel.getActListData(this,paramsMap).observe(this, actListCard -> {
                //update ui
                LogUtils.e(LOG_TAG, "请求成功");
                if (actListCard != null) {
                    binding.bigActTitle.setText(actListCard.title);
                    binding.smallActTitle.setText(actListCard.desc);
    
                    boolean hasMore = false;
                    currPage = actListCard.currPage;
                    if (currPage == 1) {
                        actListAdapter.setData(actListCard.list);
                        Log.d(LOG_TAG, "setData" + currPage);
                    } else {
                        actListAdapter.addData(actListCard.list);
                        Log.d(LOG_TAG, "addData" + currPage);
                    }
                    hasMore = currPage < actListCard.pageTotal;
                    actListAdapter.setHasMore(hasMore);
                    binding.rvActList.notifyMoreFinish(hasMore);
                }
            });
        }
    }

    展开全文
  • 1、单张图片上传 private void setHttpPortrait(final String name, final String strPath) {//name:参数名称;strPath:图片路径 File file = new File(strPath); RequestBody imageBody = RequestBody....
  • Android Retrofit @Streaming 注解失效 问题特征: 即使加了@Streaming方法也不能达到逐步加载大文件数据的效果,产生的效果为下载会有长时间的卡顿,卡顿后,会在极端的时间内加载完数据源。如图,将近100M的数据...
  • 0' 相关配置module下的build.gradle android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } 注意Retrofit和RxJava组合使用时,Retrofit中使用...
  • Retrofit应该是目前Android上最流行的网络框架之一了。那么怎么管理他的生命周期呢,总不能在每个引用的Activity或Fragment生命周期中都去手动cancel网络请求吧。接下来介绍几种实用的方法。1.借助rxjava,...
  • 前端大鸟:简单,我们是采用retrofit+okhttp的网络框架,基础url是配置的,改下就可以,敲代码… //原有Retrofit配置 new Retrofit .Builder() .baseUrl("https://xxx.xxx.x.x") .client(getOkHttpC
  • Android 使用retrofit上传图片和文字 TestService testService = RetrofitClient.getInstance().create(TestService.class); testService.upLoadFile(requestBody.build()) .subscribeOn(Schedulers.io()) ....
  • Android Retrofit Client的简单封装 前言 Retrofit 是一个 RESTful 的 HTTP 网络请求框架的封装。 使用 添加build.grade依赖 dependencies { compile 'io.reactivex.rxjava2:rxjava:2.0.1' compile 'io....
  • Android Retrofit2使用

    2021-06-06 08:39:05
    Android Retrofit2是什么?Android Retrofit2是一个安全的为Android和Java开发的Http访问框架,它是对OkHttp的进一步封装,它对应的的git地址和官网如下:Android Retrofit2能解决什么问题?不需要自己封装具体的Http...
  • 封装点 网络Log设置(OKHTTP拦截器) url统一追加参数(OKHTTP拦截器) ...不同的BaseUrl使用不同的Retrofit实例,同一个BaseUrl下使用同一个Retrofit实例 所有Retrofit实例公用一个OkhttpClient实例 网络Log设置 .
  • 那么是怎么实现的呢,下面从源码角度进行分析,其中涉及到Android异步机制(Handler、Message、Looper、MessageQueue),猿们自行脑补。二、Retrofit的创建下面从Retrofit的创建开始,其中的秘密也在其中Retrofit ...
  • 我真的不知道如何解决这个问题,这个项目它是一个Android和iOs应用程序与Docker容器服务器上的RoR后端API ...Android Retrofit和OkHttpClient错误在后端SSL握手让我们加密认证在Android应用程序中,我使用了Retrofit...
  • Retrofit是Square开发的一个Android和Java的REST客户端库。这个库非常简单并且具有很多特性,相比其他的网络库,更容易让初学者快速掌握。它可以处理GET、POST、PUT、DELETE…等请求,还可以使用picasso加载图片。一...
  • Android Retrofit简介

    2021-06-08 07:15:57
    (3)创建用于描述网络请求的接口​​​​​​​ //获取API GitHubService service = retrofit.create(GitHubService.class); //定义 网络API 地址 public interface GitHubService { @GET("users/{user}/repos") ...
  • Android retrofit上传文件

    千次阅读 2021-12-06 23:15:47
    接口 @Multipart @POST("app/updatehead")//接口 Call<ResponseBody> updateshead(@Query("user_id")String user_id,@Part MultipartBody.Part body);// 请求方法 File file = new File(file_path);...
  • 说明:在实际开发中,可能会存在需要先请求A接口,再去请求B接口的情况。比如需要请求获取收藏文章列表,但是需要先登录拿到Cookie才能请求收藏文章列表接口,...implementation "com.squareup.retrofit2:adapter-rxj.
  • 以前都是使用Observable login(@HeaderMap Map headers, @QueryMap Map map);@QueryMap方式,将参数放入map中传输的现在改用RequestBody的方式Observable login(@HeaderMap Map headers, @Body RequestBody request...
  • Retrofit实现文件和图片一起上传 如果对retrofit不是很了解,参考:初识Retrofit 定义接口 图片和字符串同时上报 @Multipart @POST("upload/") Call register( @Query("name") String cardName, @Query("phone") ...
  • 上传文件主要就是通过接口 1.AndroidMainfest.xml中加入权限 添加依赖 /... } } 以上这篇Android retrofit上传文件实例(包含头像)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
  • Android retrofit请求

    2021-04-09 10:39:31
    一、添加依赖 implementation ‘com.squareup.retrofit2:retrofit:2.0.0-beta4’ ...public Retrofit getRetrofit(){ if(build == null){ //关闭自动重连 OkHttpClient.Builder builder = new OkHttpClient
  • 入门篇保证基本使用 能看懂 且没封装前期准备app的gradle文件里compile ‘com.squareup.retrofit:retrofit:2.0.0-beta2’compile ‘com.squareup.okhttp:okhttp:2.5.0’// 网络请求 同时依赖compile ...
  • //retrofit:2.3.0 里面引用了 okhttp:3.8.0 compile 'com.squareup.retrofit2:retrofit:2.3.0' //converter-gson:2.3.0 里面引用了 gson:2.7.0 compile 'com.squareup.retrofit2:converter-gson:2.3.0' ...
  • Rxjava+Retrofit实现网络请求前言...Android Retrofit网络请求框架 Android RxJava3入门 操作 添加依赖 //retrofit与Rxjava3结合 implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0' 添加依赖 ...
  • java单例中使用weakreference的对象是否可以被回收retrofit是够需要使用单例 将retrofit放入weakreference中public class RetrofitSingleton {private WeakReference retrofitWeakReference;private ...
  • Android Retrofit详解

    2021-11-20 16:47:08
    前言 Retrofit 是一个 RESTful ...1.添加Retrofit库的依赖: implementation 'com.squareup.retrofit2:retrofit:2.0.2' implementation 'com.squareup.retrofit2:converter-gson:2.0.2' implementation 'com.google.

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 38,179
精华内容 15,271
关键字:

androidretrofit