Example usage for org.apache.http.client.utils URLEncodedUtils format

List of usage examples for org.apache.http.client.utils URLEncodedUtils format

Introduction

In this page you can find the example usage for org.apache.http.client.utils URLEncodedUtils format.

Prototype

public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) 

Source Link

Document

Returns a String that is suitable for use as an application/x-www-form-urlencoded list of parameters in an HTTP PUT or HTTP POST.

Usage

From source file:im.delight.android.webrequest.WebRequest.java

/** Builds the HTTP query string from the list of parameters (analogous to PHP's http_build_query(...) function) */
protected static String httpBuildQuery(List<? extends NameValuePair> parameters, String encoding) {
    return URLEncodedUtils.format(parameters, encoding).replace("*", "%2A");
}

From source file:de.geeksfactory.opacclient.apis.SISIS.java

public SearchRequestResult volumeSearch(Map<String, String> query) throws IOException, OpacErrorException {
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("methodToCall", "volumeSearch"));
    params.add(new BasicNameValuePair("dbIdentifier", query.get("dbIdentifier")));
    params.add(new BasicNameValuePair("catKey", query.get("catKey")));
    params.add(new BasicNameValuePair("periodical", "N"));
    String html = httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING);
    return parse_search(html, 1);
}

From source file:com.hollowsoft.library.utility.request.HttpRequest.java

/**
 *
 * @param url/* ww w . jav a 2  s  .c o  m*/
 * @param nameValuePairList
 * @return
 * @throws RequestException
 */
public JsonNode doDelete(final String url, final List<NameValuePair> nameValuePairList)
        throws RequestException {

    if (url == null || url.isEmpty()) {
        throw new IllegalArgumentException("The url cannot be null or empty.");
    }

    final String parameterString = URLEncodedUtils.format(nameValuePairList, Constants.DEFAULT_CHARSET.name());

    try {

        final HttpDelete httpDelete = new HttpDelete(url + "?" + parameterString);

        final HttpEntity httpEntity = httpClient.execute(httpDelete).getEntity();

        return new ObjectMapper().reader().readTree(httpEntity.getContent());

    } catch (final ClientProtocolException e) {
        throw new RequestException(e);

    } catch (final JsonProcessingException e) {
        throw new RequestException(e);

    } catch (final IllegalStateException e) {
        throw new RequestException(e);

    } catch (final IOException e) {
        throw new RequestException(e);
    }
}

From source file:org.auraframework.test.AuraHttpTestCase.java

/**
 * Build a URL for a get from the given parameters with all the standard parameters set from a descriptor.
 *
 * This is a convenience function to make gets more consistent. It sets:
 * <ul>/*from  w w  w . j  a  v a2 s .c  o  m*/
 *   <li>aura.tag: the name of the descriptor to get.</li>
 *   <li>aura.defType: the type of the descriptor.</li>
 *   <li>aura.context: the context, including
 *     <ul>
 *       <li>loaded: the descriptor + type from above.</li>
 *       <li>fwUID: the framework UID</li>
 *       <li>mode: from the parameters</li>
 *       <li>format: from the parameters</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * @param mode the Aura mode to use.
 * @param format the format (HTML vs JSON) to use
 * @param desc the descriptor to set as the primary object.
 * @param params extra parameters to set.
 * @param headers extra headers.
 */
protected HttpGet obtainAuraGetMethod(Mode mode, Format format, DefDescriptor<? extends BaseComponentDef> desc,
        Map<String, String> params, Header[] headers)
        throws QuickFixException, MalformedURLException, URISyntaxException {
    List<NameValuePair> urlparams = Lists.newArrayList();
    urlparams.add(
            new BasicNameValuePair("aura.tag", String.format("%s:%s", desc.getNamespace(), desc.getName())));
    urlparams.add(new BasicNameValuePair("aura.defType", desc.getDefType().toString()));

    for (Map.Entry<String, String> entry : params.entrySet()) {
        urlparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }
    urlparams.add(
            new BasicNameValuePair("aura.context", getAuraTestingUtil().getContext(mode, format, desc, false)));
    String query = URLEncodedUtils.format(urlparams, "UTF-8");

    // final url Request to be send to server
    return obtainGetMethod("aura?" + query, true, headers);
}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

/**
 * Register: /*www. j a va 2s.  com*/
 */
public ApiInvoker<LoginRet> register(String userId, String password, String nickName, String signature) {
    String[] paramNames = new String[] { "userId", "pwd", "nickname", "signature" };
    String[] paramValues = new String[] { "" + userId, "" + password, "" + nickName, "" + signature };
    String url = apiUrl.getRegisterUrl();
    ApiDataParseHandler<LoginRet> handler = ApiDataParseHandler.LOGIN_RET_PARSE_HANDLER;
    List<NameValuePair> nvps = createRequestParams(paramNames, paramValues, false, null, userId, password);
    if (Logger.DEBUG) {
        L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
    }
    return new ApiInvoker<LoginRet>(this.config, handler, url, nvps);
}

From source file:com.prey.net.PreyRestHttpClient.java

public PreyHttpResponse get(String url, Map<String, String> params, PreyConfig preyConfig, String user,
        String pass) throws IOException {
    HttpGet method = null;//from  w  w  w.  j a  va  2  s  . co m
    if (params != null) {
        method = new HttpGet(url + URLEncodedUtils.format(getHttpParamsFromMap(params), "UTF-8"));
    } else {
        method = new HttpGet(url);
    }
    method.setHeader("Accept", "*/*");
    method.addHeader("Authorization", "Basic " + getCredentials(user, pass));
    //PreyLogger.d("Sending using 'GET' (Basic Authentication) - URI: " + method.getURI());
    HttpResponse httpResponse = httpclient.execute(method);
    PreyHttpResponse response = new PreyHttpResponse(httpResponse);
    //PreyLogger.d("Response from server: " + response.toString());
    method.removeHeaders("Authorization");
    return response;
}

From source file:de.geeksfactory.opacclient.apis.Zones22.java

@Override
public DetailledItem getResultById(String id, String homebranch) throws IOException, NotReachableException {

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

    params.add(new BasicNameValuePair("Style", "Portal3"));
    params.add(new BasicNameValuePair("SubStyle", ""));
    params.add(new BasicNameValuePair("Lang", "GER"));
    params.add(new BasicNameValuePair("ResponseEncoding", "utf-8"));
    params.add(new BasicNameValuePair("no", id));

    String html = httpGet(opac_url + "/APS_PRESENT_BIB?" + URLEncodedUtils.format(params, "UTF-8"),
            getDefaultEncoding());/*from   w ww  .  ja  v a 2 s. c  om*/

    return parse_result(id, html);
}

From source file:gtu.youtube.JavaYoutubeVideoUrlHandler.java

private URI getUri(String path, List<NameValuePair> qparams) throws URISyntaxException {
    URI uri = URIUtils.createURI(scheme, host, -1, "/" + path,
            URLEncodedUtils.format(qparams, DEFAULT_ENCODING), null);
    return uri;//from   w ww  . j av a 2s.co  m
}

From source file:at.orz.arangodb.http.HttpManager.java

private static String buildUrl(HttpRequestEntity requestEntity) {
    if (requestEntity.parameters != null && !requestEntity.parameters.isEmpty()) {
        String paramString = URLEncodedUtils.format(toList(requestEntity.parameters), "utf-8");
        if (requestEntity.url.contains("?")) {
            return requestEntity.url + "&" + paramString;
        } else {//from w w w  .ja  v a 2s.c o  m
            return requestEntity.url + "?" + paramString;
        }
    }
    return requestEntity.url;
}