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();
}
Aggregations