List of usage examples for org.apache.http.message BasicNameValuePair getValue
public String getValue()
From source file:com.appassit.http.ApiRequestFactory.java
/** * GETurl//from w ww .j av a 2s .c om * * @param url * @param params * @return */ private static String getGetRequestUrl(String url, ArrayList<BasicNameValuePair> params) { if (params == null || params.size() == 0) { return url; } StringBuilder builder = new StringBuilder(); builder.append(url).append("?"); for (BasicNameValuePair entry : params) { Object obj = entry.getValue(); if (obj == null) continue; builder.append(entry.getName()).append("=").append(entry.getValue()).append("&"); } builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
From source file:Main.java
public static HttpEntity getEntity(String uri, ArrayList<BasicNameValuePair> params, int method) throws ClientProtocolException, IOException { mClient = new DefaultHttpClient(); HttpUriRequest request = null;//from ww w.ja va2s. c om switch (method) { case METHOD_GET: StringBuilder sb = new StringBuilder(uri); if (params != null && !params.isEmpty()) { sb.append("?"); for (BasicNameValuePair param : params) { sb.append(param.getName()).append("=").append(URLEncoder.encode(param.getValue(), "UTF_8")) .append("&"); } sb.deleteCharAt(sb.length() - 1); } request = new HttpGet(sb.toString()); break; case METHOD_POST: HttpPost post = new HttpPost(uri); if (params != null && !params.isEmpty()) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF_8"); post.setEntity(entity); } request = post; break; } mClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); mClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000); HttpResponse response = mClient.execute(request); System.err.println(response.getStatusLine().toString()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity(); } return null; }
From source file:com.groupon.odo.tests.HttpUtils.java
public static String doProxyGet(String url, BasicNameValuePair[] data) throws Exception { String fullUrl = url;//from w ww. j av a2 s .c o m if (data != null) { if (data.length > 0) { fullUrl += "?"; } for (BasicNameValuePair bnvp : data) { fullUrl += bnvp.getName() + "=" + uriEncode(bnvp.getValue()) + "&"; } } HttpGet get = new HttpGet(fullUrl); int port = Utils.getSystemPort(Constants.SYS_HTTP_PORT); HttpHost proxy = new HttpHost("localhost", port); HttpClient client = new org.apache.http.impl.client.DefaultHttpClient(); client.getParams().setParameter(org.apache.http.conn.params.ConnRoutePNames.DEFAULT_PROXY, proxy); HttpResponse response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String accumulator = ""; String line = ""; Boolean firstLine = true; while ((line = rd.readLine()) != null) { accumulator += line; if (!firstLine) { accumulator += "\n"; } else { firstLine = false; } } return accumulator; }
From source file:com.groupon.odo.tests.HttpUtils.java
public static String doProxyHttpsGet(String url, BasicNameValuePair[] data) throws Exception { String fullUrl = url;//from w w w . j a v a 2s . c om if (data != null) { if (data.length > 0) { fullUrl += "?"; } for (BasicNameValuePair bnvp : data) { fullUrl += bnvp.getName() + "=" + uriEncode(bnvp.getValue()) + "&"; } } TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { } URL uri = new URL(fullUrl); int port = Utils.getSystemPort(Constants.SYS_FWD_PORT); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port)); URLConnection connection = uri.openConnection(proxy); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String accumulator = ""; String line = ""; Boolean firstLine = true; while ((line = rd.readLine()) != null) { accumulator += line; if (!firstLine) { accumulator += "\n"; } else { firstLine = false; } } return accumulator; }
From source file:com.appnexus.opensdk.ANJAMImplementation.java
private static void loadResult(WebView webView, String cb, List<BasicNameValuePair> paramsList) { StringBuilder params = new StringBuilder(); params.append("cb=").append(cb != null ? cb : "-1"); if (paramsList != null) { for (BasicNameValuePair pair : paramsList) { if ((pair.getName() != null) && (pair.getValue() != null)) { params.append("&").append(pair.getName()).append("=").append(Uri.encode(pair.getValue())); }/* ww w . j a va2 s .c o m*/ } } String url = String.format("javascript:window.sdkjs.client.result(\"%s\")", params.toString()); webView.loadUrl(url); }
From source file:com.appdynamics.demo.gasp.service.RESTIntentService.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {//from w w w . java 2 s . c om if (params == null) { request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect: " + uri.toString(), e); } }
From source file:br.com.vpsa.oauth2android.response.StringParser.java
public static List<NameValuePair> parseForParameters(String stringResponse) throws JSONException, InvalidRequestException, InvalidClientException, InvalidGrantException, UnauthorizedClientException, UnsupportedGrantTypeException, InvalidScopeException, OAuthException { OAuthException exception = null;// w w w.j ava2 s .co m List<NameValuePair> parameterList = new ArrayList<NameValuePair>(); String[] parameters = stringResponse.split("&"); for (String parameter : parameters) { if (parameter.contains("?")) { parameterList.add(new BasicNameValuePair("redirectUri", parameter.split("?")[0])); parameter = parameter.split("?")[1]; } if (parameter.contains("=")) { String[] pair = parameter.split("="); BasicNameValuePair basicNameValuePair = new BasicNameValuePair(pair[0], pair[1]); parameterList.add(basicNameValuePair); if (basicNameValuePair.getName().equalsIgnoreCase("error")) { exception = ErrorParser.getException(basicNameValuePair.getValue()); } } } if (exception != null) { throw exception; } return parameterList; }
From source file:com.cloudbees.gasp.service.RESTService.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {/*from w w w.j a v a2s . c o m*/ if (params == null) { // No params were given or they have already been // attached to the Uri. request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect: " + uri.toString(), e); } }
From source file:vn.chodientu.component.imboclient.util.TextUtils.java
/** * Join a set of query params with a given delimiter, optionally URL-encoded * * @param delimiter Which delimiter (character(s)) to use for separating tokens * @param tokens Tokens to separate/*from w ww.jav a2 s .c o m*/ * @return String, with the delimiter between each token */ public static String join(CharSequence delimiter, Iterable<BasicNameValuePair> tokens, boolean urlEncode) { StringBuilder sb = new StringBuilder(); boolean firstTime = true; for (BasicNameValuePair queryParam : tokens) { if (firstTime) { firstTime = false; } else { sb.append(delimiter); } sb.append(queryParam.getName() + "=" + (urlEncode ? TextUtils.urlEncode(queryParam.getValue()) : queryParam.getValue())); } return sb.toString(); }
From source file:com.cloudbees.gasp.loader.RESTLoader.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {// w ww . j a v a 2 s .co m if (params == null) { // No params were given or they have already been // attached to the Uri. request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect: " + uri.toString()); } }