|
18 | 18 |
|
19 | 19 | package com.loopj.android.http;
|
20 | 20 |
|
| 21 | +import android.util.Log; |
| 22 | + |
21 | 23 | import org.apache.http.HttpEntity;
|
22 | 24 | import org.apache.http.client.entity.UrlEncodedFormEntity;
|
23 | 25 | import org.apache.http.client.utils.URLEncodedUtils;
|
|
88 | 90 | */
|
89 | 91 | public class RequestParams {
|
90 | 92 |
|
| 93 | + protected final static String LOG_TAG = "RequestParams"; |
91 | 94 | protected boolean isRepeatable;
|
92 | 95 | protected boolean useJsonStreamer;
|
93 | 96 | protected ConcurrentHashMap<String, String> urlParams;
|
94 | 97 | protected ConcurrentHashMap<String, StreamWrapper> streamParams;
|
95 | 98 | protected ConcurrentHashMap<String, FileWrapper> fileParams;
|
96 | 99 | protected ConcurrentHashMap<String, Object> urlParamsWithObjects;
|
| 100 | + protected String contentEncoding = HTTP.UTF_8; |
| 101 | + |
| 102 | + /** |
| 103 | + * Sets content encoding for return value of {@link #getParamString()} and {@link |
| 104 | + * #createFormEntity()} <p> </p> Default encoding is "UTF-8" |
| 105 | + * |
| 106 | + * @param encoding String constant from {@link org.apache.http.protocol.HTTP} |
| 107 | + */ |
| 108 | + public void setContentEncoding(final String encoding) { |
| 109 | + if (encoding != null) |
| 110 | + this.contentEncoding = encoding; |
| 111 | + else |
| 112 | + Log.d(LOG_TAG, "setContentEncoding called with null attribute"); |
| 113 | + } |
97 | 114 |
|
98 | 115 | /**
|
99 | 116 | * Constructs a new empty {@code RequestParams} instance.
|
@@ -378,9 +395,10 @@ private HttpEntity createJsonStreamerEntity() throws IOException {
|
378 | 395 |
|
379 | 396 | private HttpEntity createFormEntity() {
|
380 | 397 | try {
|
381 |
| - return new UrlEncodedFormEntity(getParamsList(), HTTP.UTF_8); |
| 398 | + return new UrlEncodedFormEntity(getParamsList(), contentEncoding); |
382 | 399 | } catch (UnsupportedEncodingException e) {
|
383 |
| - return null; // Actually cannot happen when using utf-8 |
| 400 | + Log.e(LOG_TAG, "createFormEntity failed", e); |
| 401 | + return null; // Can happen, if the 'contentEncoding' won't be HTTP.UTF_8 |
384 | 402 | }
|
385 | 403 | }
|
386 | 404 |
|
@@ -472,7 +490,7 @@ private List<BasicNameValuePair> getParamsList(String key, Object value) {
|
472 | 490 | }
|
473 | 491 |
|
474 | 492 | protected String getParamString() {
|
475 |
| - return URLEncodedUtils.format(getParamsList(), HTTP.UTF_8); |
| 493 | + return URLEncodedUtils.format(getParamsList(), contentEncoding); |
476 | 494 | }
|
477 | 495 |
|
478 | 496 | public static class FileWrapper {
|
|
0 commit comments