Search in sources :

Example 1 with BodyParamsEntity

use of com.lidroid.xutils.http.client.entity.BodyParamsEntity in project xUtils by wyouflf.

the class RequestParams method getEntity.

/**
     * Returns an HttpEntity containing all request parameters
     */
public HttpEntity getEntity() {
    if (bodyEntity != null) {
        return bodyEntity;
    }
    HttpEntity result = null;
    if (fileParams != null && !fileParams.isEmpty()) {
        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT, null, Charset.forName(charset));
        if (bodyParams != null && !bodyParams.isEmpty()) {
            for (NameValuePair param : bodyParams) {
                try {
                    multipartEntity.addPart(param.getName(), new StringBody(param.getValue()));
                } catch (UnsupportedEncodingException e) {
                    LogUtils.e(e.getMessage(), e);
                }
            }
        }
        for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) {
            multipartEntity.addPart(entry.getKey(), entry.getValue());
        }
        result = multipartEntity;
    } else if (bodyParams != null && !bodyParams.isEmpty()) {
        result = new BodyParamsEntity(bodyParams, charset);
    }
    return result;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) ContentBody(com.lidroid.xutils.http.client.multipart.content.ContentBody) MultipartEntity(com.lidroid.xutils.http.client.multipart.MultipartEntity) StringBody(com.lidroid.xutils.http.client.multipart.content.StringBody) BodyParamsEntity(com.lidroid.xutils.http.client.entity.BodyParamsEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

BodyParamsEntity (com.lidroid.xutils.http.client.entity.BodyParamsEntity)1 MultipartEntity (com.lidroid.xutils.http.client.multipart.MultipartEntity)1 ContentBody (com.lidroid.xutils.http.client.multipart.content.ContentBody)1 StringBody (com.lidroid.xutils.http.client.multipart.content.StringBody)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HttpEntity (org.apache.http.HttpEntity)1 NameValuePair (org.apache.http.NameValuePair)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1