use of cz.msebera.android.httpclient.message.BasicNameValuePair in project android-async-http by loopj.
the class RequestParams method getParamsList.
private List<BasicNameValuePair> getParamsList(String key, Object value) {
List<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();
if (value instanceof Map) {
Map map = (Map) value;
List list = new ArrayList<Object>(map.keySet());
// Ensure consistent ordering in query string
if (list.size() > 0 && list.get(0) instanceof Comparable) {
Collections.sort(list);
}
for (Object nestedKey : list) {
if (nestedKey instanceof String) {
Object nestedValue = map.get(nestedKey);
if (nestedValue != null) {
params.addAll(getParamsList(key == null ? (String) nestedKey : String.format(Locale.US, "%s[%s]", key, nestedKey), nestedValue));
}
}
}
} else if (value instanceof List) {
List list = (List) value;
int listSize = list.size();
for (int nestedValueIndex = 0; nestedValueIndex < listSize; nestedValueIndex++) {
params.addAll(getParamsList(String.format(Locale.US, "%s[%d]", key, nestedValueIndex), list.get(nestedValueIndex)));
}
} else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
int arrayLength = array.length;
for (int nestedValueIndex = 0; nestedValueIndex < arrayLength; nestedValueIndex++) {
params.addAll(getParamsList(String.format(Locale.US, "%s[%d]", key, nestedValueIndex), array[nestedValueIndex]));
}
} else if (value instanceof Set) {
Set set = (Set) value;
for (Object nestedValue : set) {
params.addAll(getParamsList(key, nestedValue));
}
} else {
params.add(new BasicNameValuePair(key, value.toString()));
}
return params;
}
use of cz.msebera.android.httpclient.message.BasicNameValuePair in project android-async-http by loopj.
the class RequestParams method createMultipartEntity.
private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
entity.setIsRepeatable(isRepeatable);
// Add string params
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
entity.addPartWithCharset(entry.getKey(), entry.getValue(), contentEncoding);
}
// Add non-string params
List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
for (BasicNameValuePair kv : params) {
entity.addPartWithCharset(kv.getName(), kv.getValue(), contentEncoding);
}
// Add stream params
for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
StreamWrapper stream = entry.getValue();
if (stream.inputStream != null) {
entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
}
}
// Add file params
for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
FileWrapper fileWrapper = entry.getValue();
entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType, fileWrapper.customFileName);
}
// Add file collection
for (ConcurrentHashMap.Entry<String, List<FileWrapper>> entry : fileArrayParams.entrySet()) {
List<FileWrapper> fileWrapper = entry.getValue();
for (FileWrapper fw : fileWrapper) {
entity.addPart(entry.getKey(), fw.file, fw.contentType, fw.customFileName);
}
}
return entity;
}
use of cz.msebera.android.httpclient.message.BasicNameValuePair in project AndroidStudy by tinggengyan.
the class HttpCookie method run.
@Override
public void run() {
list.add(new BasicNameValuePair("name", "steve"));
list.add(new BasicNameValuePair("age", "12"));
try {
post.setEntity(new UrlEncodedFormEntity(list));
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
AbstractHttpClient absclient = (AbstractHttpClient) client;
List<Cookie> cookies = absclient.getCookieStore().getCookies();
for (Cookie cookie : cookies) {
System.out.println("name==" + cookie.getName());
System.out.println("value==" + cookie.getValue());
Message message = new Message();
message.obj = cookie;
mHandler.sendMessage(message);
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of cz.msebera.android.httpclient.message.BasicNameValuePair in project android-async-http by loopj.
the class RequestParams method getParamsList.
protected List<BasicNameValuePair> getParamsList() {
List<BasicNameValuePair> lparams = new LinkedList<BasicNameValuePair>();
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
lparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
lparams.addAll(getParamsList(null, urlParamsWithObjects));
return lparams;
}
use of cz.msebera.android.httpclient.message.BasicNameValuePair in project android-async-http by loopj.
the class RequestParams method toString.
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
if (result.length() > 0)
result.append("&");
result.append(entry.getKey());
result.append("=");
result.append(entry.getValue());
}
for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
if (result.length() > 0)
result.append("&");
result.append(entry.getKey());
result.append("=");
result.append("STREAM");
}
for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
if (result.length() > 0)
result.append("&");
result.append(entry.getKey());
result.append("=");
result.append("FILE");
}
for (ConcurrentHashMap.Entry<String, List<FileWrapper>> entry : fileArrayParams.entrySet()) {
if (result.length() > 0)
result.append("&");
result.append(entry.getKey());
result.append("=");
result.append("FILES(SIZE=").append(entry.getValue().size()).append(")");
}
List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
for (BasicNameValuePair kv : params) {
if (result.length() > 0)
result.append("&");
result.append(kv.getName());
result.append("=");
result.append(kv.getValue());
}
return result.toString();
}
Aggregations