Search in sources :

Example 31 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project xUtils by wyouflf.

the class URLEncodedUtils method parse.

/**
     * Adds all parameters within the Scanner to the list of <code>parameters</code>.
     * For example,a scanner containing the string <code>a=1&b=2&c=3</code> would
     * add the {@link org.apache.http.NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
     * list of parameters.
     *
     * @param parameters List to add parameters to.
     * @param scanner    Input that contains the parameters to parse.
     */
public static void parse(final List<NameValuePair> parameters, final Scanner scanner) {
    scanner.useDelimiter(PARAMETER_SEPARATOR);
    while (scanner.hasNext()) {
        String name = null;
        String value = null;
        String token = scanner.next();
        int i = token.indexOf(NAME_VALUE_SEPARATOR);
        if (i != -1) {
            name = token.substring(0, i).trim();
            value = token.substring(i + 1).trim();
        } else {
            name = token.trim();
        }
        parameters.add(new BasicNameValuePair(name, value));
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 32 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project jstorm by alibaba.

the class AlimonitorClient method httpPost.

private boolean httpPost(String url, String msg) {
    boolean ret = false;
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    CloseableHttpResponse response = null;
    try {
        HttpPost request = new HttpPost(url);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("name", monitorName));
        nvps.add(new BasicNameValuePair("msg", msg));
        request.setEntity(new UrlEncodedFormEntity(nvps));
        response = httpClient.execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            LOG.info(EntityUtils.toString(entity));
        }
        EntityUtils.consume(entity);
        ret = true;
    } catch (Exception e) {
        LOG.error("Exception when sending http request to alimonitor", e);
    } finally {
        try {
            if (response != null)
                response.close();
            httpClient.close();
        } catch (Exception e) {
            LOG.error("Exception when closing httpclient", e);
        }
    }
    return ret;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 33 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project robovm by robovm.

the class URLEncodedUtils method parse.

/**
     * Adds all parameters within the Scanner to the list of
     * <code>parameters</code>, as encoded by <code>encoding</code>. For
     * example, a scanner containing the string <code>a=1&b=2&c=3</code> would
     * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
     * list of parameters.
     * 
     * @param parameters
     *            List to add parameters to.
     * @param scanner
     *            Input that contains the parameters to parse.
     * @param encoding
     *            Encoding to use when decoding the parameters.
     */
public static void parse(final List<NameValuePair> parameters, final Scanner scanner, final String encoding) {
    scanner.useDelimiter(PARAMETER_SEPARATOR);
    while (scanner.hasNext()) {
        final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
        if (nameValue.length == 0 || nameValue.length > 2)
            throw new IllegalArgumentException("bad parameter");
        final String name = decode(nameValue[0], encoding);
        String value = null;
        if (nameValue.length == 2)
            value = decode(nameValue[1], encoding);
        parameters.add(new BasicNameValuePair(name, value));
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 34 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project Trello-Android by chrisHoekstra.

the class TrelloService method getNotifications.

public ArrayList<NotificationVO> getNotifications() {
    ArrayList<NotificationVO> result = null;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "notifications?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpGet, mContext);
        if (response != null) {
            result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<NotificationVO>>() {
            });
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) NotificationVO(com.chrishoekstra.trello.vo.NotificationVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 35 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project Trello-Android by chrisHoekstra.

the class TrelloService method addCard.

public Boolean addCard(String boardListId, String name) {
    Boolean result = false;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    params.add(new BasicNameValuePair("name", name));
    params.add(new BasicNameValuePair("idList", boardListId));
    HttpPost httpPost = new HttpPost(TRELLO_API_URL + "cards?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpPost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpPost, mContext);
        if (response != null) {
            result = true;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Aggregations

BasicNameValuePair (org.apache.http.message.BasicNameValuePair)289 NameValuePair (org.apache.http.NameValuePair)199 ArrayList (java.util.ArrayList)187 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)101 HttpPost (org.apache.http.client.methods.HttpPost)87 HttpResponse (org.apache.http.HttpResponse)77 HttpEntity (org.apache.http.HttpEntity)58 IOException (java.io.IOException)55 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)33 Test (org.junit.Test)32 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)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)23 HashMap (java.util.HashMap)20 JSONObject (org.json.JSONObject)20 Map (java.util.Map)19 URI (java.net.URI)16 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)15