retrofit 发送body raw格式参数

//登录
@POST("/clinic/app/sys_user/login")
Flowable> toLogin(@Body RequestBody map);

public class RequestBodyUtils {
    private static volatile RequestBodyUtils instance;
    private MediaType mediaType;

    private RequestBodyUtils() {
    }

    public static RequestBodyUtils getInstance() {
        if (instance == null) {
            synchronized (RequestBodyUtils.class) { //在多线程中获取需要进行同步,或者会导致同步问题
                if (instance == null)
                    instance = new RequestBodyUtils();
            }
        }
        return instance;
    }

    public RequestBody getTypeToBody(Object object) {
        if (null == mediaType) {
            mediaType = MediaType.Companion.parse("application/json;charset=utf-8");
        }
        return RequestBody.Companion.create(GsonUtil.GsonString(object), mediaType);
    }
}

使用

apis.toLogin(RequestBodyUtils.getInstance().getTypeToBody(map)

你可能感兴趣的:(Android基础,android,raw,参数,retrofit,raw,请求)