use of org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
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 org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
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.addPart(entry.getKey(), entry.getValue());
}
// Add non-string params
List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
for (BasicNameValuePair kv : params) {
entity.addPart(kv.getName(), kv.getValue());
}
// 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);
}
return entity;
}
use of org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
the class RequestParams method getParamsList.
private List<BasicNameValuePair> getParamsList(String key, Object value) {
List<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
List<String> list = new ArrayList<String>(map.keySet());
// Ensure consistent ordering in query string
Collections.sort(list);
for (String nestedKey : list) {
Object nestedValue = map.get(nestedKey);
if (nestedValue != null) {
params.addAll(getParamsList(key == null ? nestedKey : String.format("%s[%s]", key, nestedKey), nestedValue));
}
}
} else if (value instanceof List) {
List<Object> list = (List<Object>) value;
for (Object nestedValue : list) {
params.addAll(getParamsList(String.format("%s[]", key), nestedValue));
}
} else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
for (Object nestedValue : array) {
params.addAll(getParamsList(String.format("%s[]", key), nestedValue));
}
} else if (value instanceof Set) {
Set<Object> set = (Set<Object>) value;
for (Object nestedValue : set) {
params.addAll(getParamsList(key, nestedValue));
}
} else if (value instanceof String) {
params.add(new BasicNameValuePair(key, (String) value));
}
return params;
}
use of org.apache.http.message.BasicNameValuePair in project Anki-Android by Ramblurr.
the class Feedback method addTimestamp.
// Run in AsyncTask
private static void addTimestamp(List<NameValuePair> pairs) {
Date ts = new Date();
df1.setTimeZone(TimeZone.getTimeZone("UTC"));
String reportsentutc = String.format("%s", df1.format(ts));
String reportsenttzoffset = String.format("%s", df2.format(ts));
String reportsenttz = String.format("%s", localTz.getID());
pairs.add(new BasicNameValuePair("reportsentutc", reportsentutc));
pairs.add(new BasicNameValuePair("reportsenttzoffset", reportsenttzoffset));
pairs.add(new BasicNameValuePair("reportsenttz", reportsenttz));
}
use of org.apache.http.message.BasicNameValuePair in project Notes by MiCode.
the class GTaskClient method postRequest.
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
throw new ActionFailureException("not logged in");
}
HttpPost httpPost = createHttpPost();
try {
LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
list.add(new BasicNameValuePair("r", js.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
httpPost.setEntity(entity);
// execute the post
HttpResponse response = mHttpClient.execute(httpPost);
String jsString = getResponseContent(response.getEntity());
return new JSONObject(jsString);
} catch (ClientProtocolException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("postRequest failed");
} catch (IOException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("postRequest failed");
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("unable to convert response content to jsonobject");
} catch (Exception e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("error occurs when posting request");
}
}
Aggregations