Search in sources :

Example 1 with FormParams

use of pers.lizechao.android_lib.net.params.FormParams in project lzc_app_lib by httplzc.

the class OkHttpCallFactory method transToRequest.

private Request transToRequest(RequestData requestData) {
    String url = requestData.url;
    BaseParams params = requestData.params;
    HttpMethod method = requestData.method;
    HttpUrl httpUrl = HttpUrl.parse(url);
    Objects.requireNonNull(httpUrl);
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.headers(Headers.of(params.getHeads()));
    RequestBody body = null;
    if (method == HttpMethod.GET || method == HttpMethod.HEAD) {
        if (!(params instanceof FormParams))
            throw new IllegalArgumentException(method.name() + "只能为表单数据");
        httpUrl = paramsToHttpUrl(httpUrl, (FormParams) params);
    } else {
        if (params instanceof RawParams) {
            body = transToBody(((RawParams) params).getBinaryData());
        } else if (params instanceof MultipartFormParams) {
            body = transToBody((MultipartFormParams) params);
        } else if (params instanceof FormParams) {
            body = transToBody((FormParams) params);
        }
    }
    if (body != null)
        body = new ProxyRequestBody(body, requestData.uploadProgress);
    return requestBuilder.url(httpUrl).method(method.name(), body).build();
}
Also used : MultipartFormParams(pers.lizechao.android_lib.net.params.MultipartFormParams) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) FormParams(pers.lizechao.android_lib.net.params.FormParams) MultipartFormParams(pers.lizechao.android_lib.net.params.MultipartFormParams) RawParams(pers.lizechao.android_lib.net.params.RawParams) BaseParams(pers.lizechao.android_lib.net.params.BaseParams) HttpMethod(pers.lizechao.android_lib.net.base.HttpMethod) RequestBody(okhttp3.RequestBody)

Example 2 with FormParams

use of pers.lizechao.android_lib.net.params.FormParams in project lzc_app_lib by httplzc.

the class ApiRequestCreater method createBaseParams.

private BaseParams createBaseParams(Object[] args, Params[] params, ParamsType paramsType) {
    BaseParams.Builder builder = createParamsByType(paramsType);
    FormParams comment = Optional.ofNullable(paramsBuilderFactory).map(ComParamsBuilderFactory::createBuilder).orElse(new FormParams.Builder().build());
    if (paramsType != ParamsType.Raw) {
        builder.putParams(comment);
    }
    builder.putBeanByData(args, params, new String[args.length]);
    return builder.build();
}
Also used : FormParams(pers.lizechao.android_lib.net.params.FormParams) MultipartFormParams(pers.lizechao.android_lib.net.params.MultipartFormParams) BaseParams(pers.lizechao.android_lib.net.params.BaseParams)

Aggregations

BaseParams (pers.lizechao.android_lib.net.params.BaseParams)2 FormParams (pers.lizechao.android_lib.net.params.FormParams)2 MultipartFormParams (pers.lizechao.android_lib.net.params.MultipartFormParams)2 HttpUrl (okhttp3.HttpUrl)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 HttpMethod (pers.lizechao.android_lib.net.base.HttpMethod)1 RawParams (pers.lizechao.android_lib.net.params.RawParams)1