Example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair

List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair

Introduction

In this page you can find the example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair.

Prototype

public BasicNameValuePair(String str, String str2) 

Source Link

Usage

From source file:org.jenkinsci.plugins.fabric8.support.HubotClient.java

public static String notify(TaskListener listener, String room, String message) throws java.io.IOException {
    log(listener, "Hubot sending to room " + room + " => " + message);
    if (Strings.isNullOrBlank(room)) {
        log(listener, "you must specify a room!");
        return null;
    }//w ww  .  j  a v a 2s  . c o  m
    if (Strings.isNullOrBlank(message)) {
        log(listener, "you must specify a message!");
        return null;
    }
    HttpHost host = RestClient.getHttpHost(listener, "hubot");
    if (host != null) {
        String roomWithSlugPrefix = room;
        if (roomWithSlugPrefix.startsWith("#")) {
            roomWithSlugPrefix = roomWithSlugPrefix.substring(1);
        }
        if (!roomWithSlugPrefix.startsWith(ROOM_SLUG_PREFIX)) {
            roomWithSlugPrefix = ROOM_SLUG_PREFIX + roomWithSlugPrefix;
        }
        HttpPost post = new HttpPost("/hubot/notify/" + roomWithSlugPrefix);
        log(listener, "Posting to " + host.toString() + " url: " + post.getURI());

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("message", message));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        CloseableHttpResponse response = RestClient.executeRequest(host, post);
        String result = RestClient.parse(response);
        log(listener, "Result: " + result);
        return result;
    } else {
        log(listener, "No service found!");
        return null;
    }
}

From source file:com.ratebeer.android.api.command.SetEventAttendanceCommand.java

@Override
protected void makeRequest(ApiConnection apiConnection) throws ApiException {
    ApiConnection.ensureLogin(apiConnection, getUserSettings());
    apiConnection.post("http://www.ratebeer.com/eventprocess-attend.asp",
            Arrays.asList(new BasicNameValuePair("EventID", Integer.toString(eventId)),
                    new BasicNameValuePair("IsGoing", isGoing ? "1" : "0")),
            // Note that we get an HTTP $)$ response even when the request is successfull...
            HttpURLConnection.HTTP_NOT_FOUND);
}

From source file:com.chuck.core.filter.FilterQuery.java

/**
 * Adds a filter parameter to the query//from   w  ww. ja  v  a  2  s.  c  o m
 *
 * @param key   the parameter key
 * @param value the parameter value
 */
public void addParameter(String key, Object value) {
    parameters.add(new BasicNameValuePair(key, value.toString()));
}

From source file:fr.shywim.antoinedaniel.utils.GcmUtils.java

public static void sendRegistrationIdToBackend(Context context, String regid, int version) {
    try {//from  w w w.j  av  a 2  s . c  o m
        HttpPost post = new HttpPost(context.getString(R.string.api_register));
        List<NameValuePair> params = new ArrayList<>(2);
        params.add(new BasicNameValuePair("regid", regid));
        params.add(new BasicNameValuePair("version", Integer.toString(version)));
        post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(post);

        int responseCode = response.getStatusLine().getStatusCode();
        if (responseCode == 200 || responseCode == 201) {
            context.getSharedPreferences(AppConstants.GOOGLE_PREFS, Context.MODE_PRIVATE).edit()
                    .putBoolean(AppConstants.GOOGLE_GCM_REGISTERED, true).apply();
        }
    } catch (IOException e) {
        Crashlytics.logException(e);
    }
}

From source file:dk.i2m.drupal.field.wrapper.OptionWrapper.java

@Override
public Set<NameValuePair> setup(String language, Set<NameValuePair> nvps) {
    for (int i = 0; i < options.size(); i++) {
        Option option = options.get(i);

        if (option.getValue() != null) {
            nvps.add(new BasicNameValuePair(name + "[" + language + "]" + "[" + i + "]",
                    (option.getValue() ? "1" : "0")));
        }/*from  w w w .jav  a2 s . c  om*/
    }

    return nvps;
}

From source file:org.lol.reddit.reddit.RedditAPI.java

public static void submit(final CacheManager cm, final APIResponseHandler.ActionResponseHandler responseHandler,
        final RedditAccount user, final boolean is_self, final String subreddit, final String title,
        final String body, final String captchaId, final String captchaText, final Context context) {

    final LinkedList<NameValuePair> postFields = new LinkedList<NameValuePair>();
    postFields.add(new BasicNameValuePair("kind", is_self ? "self" : "link"));
    postFields.add(new BasicNameValuePair("sendreplies", "true"));
    postFields.add(new BasicNameValuePair("uh", user.modhash));
    postFields.add(new BasicNameValuePair("sr", subreddit));
    postFields.add(new BasicNameValuePair("title", title));
    postFields.add(new BasicNameValuePair("captcha", captchaText));
    postFields.add(new BasicNameValuePair("iden", captchaId));

    if (is_self)/*from   w w  w .j  a v a2 s. c om*/
        postFields.add(new BasicNameValuePair("text", body));
    else
        postFields.add(new BasicNameValuePair("url", body));

    cm.makeRequest(new APIPostRequest(Constants.Reddit.getUri("/api/submit"), user, postFields, context) {

        @Override
        public void onJsonParseStarted(JsonValue result, long timestamp, UUID session, boolean fromCache) {

            System.out.println(result.toString());

            try {
                final APIResponseHandler.APIFailureType failureType = findFailureType(result);

                if (failureType != null) {
                    responseHandler.notifyFailure(failureType);
                    return;
                }

            } catch (Throwable t) {
                notifyFailure(RequestFailureType.PARSE, t, null, "JSON failed to parse");
            }

            responseHandler.notifySuccess();
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(context, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            responseHandler.notifyFailure(type, t, status, readableMessage);
        }
    });
}

From source file:com.Kuesty.services.RequestTask.java

public RequestTask addParam(String name, String value) {
    if (null == params) {
        params = new ArrayList<NameValuePair>();
    }/*  w  ww  .  j a v a2 s . co  m*/
    params.add(new BasicNameValuePair(name, value));
    return this;
}

From source file:org.dataconservancy.ui.it.support.ListProjectActivityRequest.java

public HttpPost asHttpPost(String projectId) {

    HttpPost post = null;//ww  w . j a  v a  2s.  c  o  m
    try {
        post = new HttpPost(urlConfig.getListProjectCollectionsUrl().toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("currentProjectId", projectId));
    params.add(new BasicNameValuePair(STRIPES_EVENT, "List Project Activity"));

    HttpEntity entity = null;
    try {
        entity = new UrlEncodedFormEntity(params, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    post.setEntity(entity);

    return post;
}

From source file:restApi.ApiCaller.java

@Override
protected Void doInBackground() throws IOException {

    List<NameValuePair> params = new LinkedList<NameValuePair>();

    params.add(new BasicNameValuePair("q", q));
    params.add(new BasicNameValuePair("format", format));
    params.add(new BasicNameValuePair("diagnostics", diagnostics));
    params.add(new BasicNameValuePair("env", env));

    String paramString = URLEncodedUtils.format(params, "utf-8");

    builtUrl = baseUrl + paramString;/*from  ww w. j  ava 2 s  .c  o  m*/

    HttpClient client = HttpClients.createDefault();

    HttpGet request = new HttpGet(builtUrl);

    // add request header
    request.addHeader("User-Agent", USER_AGENT);

    HttpResponse response = client.execute(request);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }

    jsonStr = result.toString();

    return null;

}

From source file:com.kingja.springmvc.util.HttpRequestUtils.java

/**
 * ??HttpWeb/*from   ww  w .  j  ava  2  s  . c o  m*/
 *
 * @param path Web?
 * @param map Http?
 * @param encode ??
 * @return Web?
 */
public String sendHttpClientPost(String path, Map<String, String> map, String encode) {
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    if (map != null && !map.isEmpty()) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            //?Map?BasicNameValuePair?
            list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
    }

    try {
        // ???HttpEntity
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, encode);
        //HttpPost?
        HttpPost httpPost = new HttpPost(path);
        //?Form
        httpPost.setEntity(entity);
        //HttpAndroidHttpClient
        CloseableHttpClient httpclient = HttpClients.createDefault();
        //??
        HttpResponse httpResponse = httpclient.execute(httpPost);
        //??200??
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            //HttpEntity??
            InputStream inputStream = httpResponse.getEntity().getContent();
            return changeInputStream(inputStream, encode);
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return "";
}