List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair
public BasicNameValuePair(String str, String str2)
From source file:org.opencastproject.remotetest.server.resource.SearchResources.java
public static HttpResponse add(TrustedHttpClient client, String mediapackage) throws Exception { HttpPost post = new HttpPost(getServiceUrl() + "add"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("mediapackage", mediapackage)); post.setEntity(new UrlEncodedFormEntity(params)); return client.execute(post); }
From source file:org.matonto.rest.util.LinksUtils.java
private static String buildQueryString(MultivaluedMap<String, String> queryParams, int start) { List<NameValuePair> params = new ArrayList<>(); queryParams.forEach((key, values) -> { if (key.equals("offset")) { params.add(new BasicNameValuePair(key, String.valueOf(start))); } else {//from w w w. j a v a 2s. co m params.add(new BasicNameValuePair(key, values.get(0))); } }); return URLEncodedUtils.format(params, '&', Charset.forName("UTF-8")); }
From source file:com.wind_now.statistics_api.latest.LatestBuilder.java
@Override public URI getUri(String title) { List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("day", "30")); params.add(new BasicNameValuePair("title", title)); return (getUri(params)); }
From source file:Main.java
public static HttpEntity buildUrlEncodedFormEntity(Map<String, String> keyValuePairs) { List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); if (keyValuePairs != null) { Set<String> keys = keyValuePairs.keySet(); for (String key : keys) { String value = keyValuePairs.get(key); BasicNameValuePair param = new BasicNameValuePair(key, value); params.add(param);/*from w w w . j ava 2 s . c om*/ } } try { return new UrlEncodedFormEntity(params); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:org.opencastproject.remotetest.server.resource.SchedulerResources.java
public static HttpResponse addEvent(TrustedHttpClient client, String event) throws Exception { HttpPut put = new HttpPut(getServiceUrl() + "event"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("event", event)); put.setEntity(new UrlEncodedFormEntity(params)); return client.execute(put); }
From source file:Main.java
public static byte[] doPostSubmit(String url, Map<String, Object> params) { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(); try {//from w w w .java 2s.c o m List<NameValuePair> list = new ArrayList<NameValuePair>(); for (Entry<String, Object> entry : params.entrySet()) { NameValuePair nameValuePair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString()); list.add(nameValuePair); } httpPost.setEntity(new UrlEncodedFormEntity(list, "utf-8")); HttpResponse response = httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); return EntityUtils.toByteArray(entity); } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.mashape.unirest.http.utils.MapUtil.java
public static List<NameValuePair> getList(Map<String, Object> parameters) { List<NameValuePair> result = new ArrayList<NameValuePair>(); if (parameters != null) { Set<String> keySet = parameters.keySet(); for (String key : keySet) { result.add(new BasicNameValuePair(key, parameters.get(key).toString())); }//from w w w . j av a 2 s .c o m } return result; }
From source file:com.peteydog7.mcstreamnotifier.twitch.Http.java
public static String sendApiGet(String urlPath, List<NameValuePair> urlParameters) throws Exception { if (Config.Value.AUTH_TOKEN != "none") { urlParameters.add(new BasicNameValuePair("oauth_token", Config.Value.AUTH_TOKEN)); }//w w w. j a v a2s.c o m URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("https"); uriBuilder.setHost(Twitch.API_BASE); uriBuilder.setPath(urlPath); uriBuilder.setParameters(urlParameters); URI url = uriBuilder.build(); HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); // add request header request.addHeader("User-Agent", USER_AGENT); request.addHeader("client_id", Twitch.CLIENT_ID); request.addHeader("Accept", Twitch.API_VERSION); HttpResponse response = client.execute(request); LogHelper.info("Sending 'GET' request to URL : " + url); LogHelper.info("Response Code : " + response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() != 200) { ThreadManager.restartThreadTwitch(); return null; } BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } return result.toString(); }
From source file:com.busan.cw.clsp20120924.gcm.ServerUtilities.java
/** * Register this account/device pair within the server. * /*w w w . jav a2 s .c o m*/ */ public static void register(final Context context, final String regId, String memberId) { l.i("registering device (regId = " + regId + ")"); final String serverUrl = CommonUtilities.SERVER_URL + "/setKey"; final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("registration_id", regId)); params.add(new BasicNameValuePair("member_seq", memberId)); // Once GCM returns a registration id, we need to register it in the // demo server. As the server might be down, we will retry it a couple // times. new Thread() { public void run() { long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000); for (int i = 1; i <= MAX_ATTEMPTS; i++) { l.i("Attempt #" + i + " to register"); try { StreamUtils.inStreamFromURL(serverUrl, params); GCMRegistrar.setRegisteredOnServer(context, true); return; } catch (IOException e) { // Here we are simplifying and retrying on any error; in // a real // application, it should retry only on unrecoverable // errors // (like HTTP error code 503). l.i("Failed to register on attempt " + i + ":" + e); if (i == MAX_ATTEMPTS) { break; } try { l.i("Sleeping for " + backoff + " ms before retry"); Thread.sleep(backoff); } catch (InterruptedException e1) { // Activity finished before we complete - exit. l.i("Thread interrupted: abort remaining retries!"); Thread.currentThread().interrupt(); return; } // increase backoff exponentially backoff *= 2; } } } }.start(); }
From source file:org.mumod.util.MustardUtil.java
public static void snapshot(Context context, String id, String version, String accountNumber) { try {/* www . j av a 2s . c o m*/ HttpPost post = new HttpPost("http://mustard.macno.org/snapshot.php"); ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("v", version)); params.add(new BasicNameValuePair("n", accountNumber)); params.add(new BasicNameValuePair("m", id)); post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpManager hm = new HttpManager(context); DefaultHttpClient hc = hm.getHttpClient(); hc.execute(post); } catch (Exception e) { } }