Search in sources :

Example 6 with BasicNameValuePair

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedList(java.util.LinkedList)

Example 7 with BasicNameValuePair

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with BasicNameValuePair

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 9 with BasicNameValuePair

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));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Date(java.util.Date)

Example 10 with BasicNameValuePair

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");
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) HttpResponse(org.apache.http.HttpResponse) JSONException(org.json.JSONException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) NetworkFailureException(net.micode.notes.gtask.exception.NetworkFailureException) IOException(java.io.IOException) ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NetworkFailureException(net.micode.notes.gtask.exception.NetworkFailureException)

Aggregations

BasicNameValuePair (org.apache.http.message.BasicNameValuePair)279 NameValuePair (org.apache.http.NameValuePair)191 ArrayList (java.util.ArrayList)178 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)96 HttpPost (org.apache.http.client.methods.HttpPost)81 HttpResponse (org.apache.http.HttpResponse)75 HttpEntity (org.apache.http.HttpEntity)57 IOException (java.io.IOException)51 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)33 Test (org.junit.Test)31 HttpGet (org.apache.http.client.methods.HttpGet)29 ClientProtocolException (org.apache.http.client.ClientProtocolException)28 CSVReader (com.talend.csv.CSVReader)27 HttpClient (org.apache.http.client.HttpClient)24 JSONObject (org.json.JSONObject)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)19 HashMap (java.util.HashMap)19 Map (java.util.Map)17 URI (java.net.URI)16 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)15