Search in sources :

Example 1 with MultipartFormParams

use of pers.lizechao.android_lib.net.params.MultipartFormParams 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)

Aggregations

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