當前位置: 首頁>>代碼示例>>Java>>正文


Java URLEncodedUtils.format方法代碼示例

本文整理匯總了Java中org.apache.http.client.utils.URLEncodedUtils.format方法的典型用法代碼示例。如果您正苦於以下問題:Java URLEncodedUtils.format方法的具體用法?Java URLEncodedUtils.format怎麽用?Java URLEncodedUtils.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.utils.URLEncodedUtils的用法示例。


在下文中一共展示了URLEncodedUtils.format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: paramString

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
protected String paramString(Map<String, ?> paramMap)
{
	List<NameValuePair> params = Lists.newArrayList();
	if( paramMap != null )
	{
		for( Entry<String, ?> paramEntry : paramMap.entrySet() )
		{
			Object value = paramEntry.getValue();
			if( value != null )
			{
				params.add(new BasicNameValuePair(paramEntry.getKey(), value.toString()));
			}
		}
	}
	return URLEncodedUtils.format(params, "UTF-8");
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:AbstractRestApiTest.java

示例2: genAddressWithoutSchema

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
private String genAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
  if (addressWithoutSchema == null || pairs == null || pairs.isEmpty()) {
    return addressWithoutSchema;
  }

  int idx = addressWithoutSchema.indexOf('?');
  if (idx == -1) {
    addressWithoutSchema += "?";
  } else {
    addressWithoutSchema += "&";
  }

  String encodedQuery = URLEncodedUtils.format(pairs.entrySet().stream().map(entry -> {
    return new BasicNameValuePair(entry.getKey(), entry.getValue());
  }).collect(Collectors.toList()), StandardCharsets.UTF_8.name());

  if (!RegistryUtils.getServiceRegistry().getFeatures().isCanEncodeEndpoint()) {
    addressWithoutSchema = genAddressWithoutSchemaForOldSC(addressWithoutSchema, encodedQuery);
  } else {
    addressWithoutSchema += encodedQuery;
  }

  return addressWithoutSchema;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:25,代碼來源:AbstractTransport.java

示例3: doSearch

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
private JsonNode doSearch(String info, String query, Map<?, ?> otherParams, String token) throws Exception
{
	List<NameValuePair> params = Lists.newArrayList();
	if( info != null )
	{
		params.add(new BasicNameValuePair("info", info));
	}
	if( query != null )
	{
		params.add(new BasicNameValuePair("q", query));
	}
	for( Entry<?, ?> entry : otherParams.entrySet() )
	{
		params.add(new BasicNameValuePair(entry.getKey().toString(), entry.getValue().toString()));
	}
	// params.add(new BasicNameValuePair("token",
	// TokenSecurity.createSecureToken(username, "token", "token", null)));
	String paramString = URLEncodedUtils.format(params, "UTF-8");
	HttpGet get = new HttpGet(context.getBaseUrl() + "api/search?" + paramString);
	HttpResponse response = execute(get, false, token);
	return mapper.readTree(response.getEntity().getContent());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:SearchApiTest.java

示例4: getUrlForGettingDoc

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
public String getUrlForGettingDoc(String q, List<String> languages, String dataSetId)
{
	List<NameValuePair> parameters = Lists.newArrayList();

	parameters.add(new BasicNameValuePair("q", getPhraseQueryString(q)));
	parameters.add(new BasicNameValuePair("defType", "edismax"));
	parameters.add(new BasicNameValuePair("lowercaseOperators", "false"));
	parameters.add(new BasicNameValuePair("rows", "100000"));
	parameters.add(new BasicNameValuePair("qs", "10"));
	parameters.add(new BasicNameValuePair("fl", Properties.idField.get() + ", " + Properties.titleFields.get().get(0) + "_en"));
	parameters.add(new BasicNameValuePair("sort", Properties.idField.get() + " DESC"));
	parameters.add(new BasicNameValuePair("qf", getQueryFields(languages)));
	parameters.add(new BasicNameValuePair("fq", Properties.docTypeFieldName.get() + ":" + dataSetId));
	parameters.add(new BasicNameValuePair("wt", "json"));

	return getServerUrl() + "/select?" + URLEncodedUtils.format(parameters, BaseIndexer.ENCODING);
}
 
開發者ID:Netflix,項目名稱:q,代碼行數:18,代碼來源:SolrSearcher.java

示例5: mergeUrlParams

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
     * 拚裝Url與參數
     *
     * @param url
     * @param params
     * @return
     */
    public static String mergeUrlParams(@NotNull String url, HashMap<String, String> params) {
        if (params == null || params.isEmpty()) {
            return url;
        }
        String[] s = splitUrl(url);
        List<NameValuePair> parse;
        if (s[1] != null) {
            parse = URLEncodedUtils.parse(s[1], Charset.defaultCharset());
        } else {
            parse = new ArrayList<>();
        }
//        System.out.println(parse);
        for (Map.Entry<String, String> entry : params.entrySet()) {
            parse.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        String p = URLEncodedUtils.format(parse, Charset.defaultCharset());
//        System.out.println(p);
        return s[0] + "?" + p;
    }
 
開發者ID:FingerArt,項目名稱:ApiDebugger,代碼行數:27,代碼來源:CommonUtil.java

示例6: getResponseJsonObject

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
private JSONObject getResponseJsonObject(String httpMethod, String url, Object params) throws IOException, MtWmErrorException {

        HttpUriRequest httpUriRequest = null;
        String fullUrl = getBaseApiUrl() + url;
        List<NameValuePair> sysNameValuePairs = getSysNameValuePairs(fullUrl, params);
        List<NameValuePair> nameValuePairs = getNameValuePairs(params);
        if (HTTP_METHOD_GET.equals(httpMethod)) {
            sysNameValuePairs.addAll(nameValuePairs);
            HttpGet httpGet = new HttpGet(fullUrl + "?" + URLEncodedUtils.format(sysNameValuePairs, UTF_8));
            setRequestConfig(httpGet);
            httpUriRequest = httpGet;
        } else if (HTTP_METHOD_POST.equals(httpMethod)) {
            HttpPost httpPost = new HttpPost(fullUrl + "?" + URLEncodedUtils.format(sysNameValuePairs, UTF_8));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, UTF_8));
            setRequestConfig(httpPost);
            httpUriRequest = httpPost;
        }

        CloseableHttpResponse response = this.httpClient.execute(httpUriRequest);
        String resultContent = new BasicResponseHandler().handleResponse(response);
        JSONObject jsonObject = JSON.parseObject(resultContent);
        MtWmError error = MtWmError.fromJson(jsonObject);
        if (error != null) {
            logging(url, httpMethod, false, httpUriRequest.getURI() + "\nBody:" + JSON.toJSONString(params), resultContent);
            throw new MtWmErrorException(error.getErrorCode(), error.getErrorMsg());
        }
        logging(url, httpMethod, true, httpUriRequest.getURI() + "\nBody:" + JSON.toJSONString(params), resultContent);
        return jsonObject;
    }
 
開發者ID:kuangcao,項目名稱:meituanwaimai-sdk,代碼行數:30,代碼來源:BaseServiceImpl.java

示例7: encodeParameters

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
 * Creates an encoded query string from all the parameters in the specified
 * request.
 *
 * @param request
 *            The request containing the parameters to encode.
 *
 * @return Null if no parameters were present, otherwise the encoded query
 *         string for the parameters present in the specified request.
 */
public static String encodeParameters(Request<?> request) {
    List<NameValuePair> nameValuePairs = null;
    if (request.getParameters().size() > 0) {
        nameValuePairs = new ArrayList<NameValuePair>(request.getParameters().size());
        for (Entry<String, String> entry : request.getParameters().entrySet()) {
            nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
    }

    String encodedParams = null;
    if (nameValuePairs != null) {
        encodedParams = URLEncodedUtils.format(nameValuePairs, DEFAULT_ENCODING);
    }

    return encodedParams;
}
 
開發者ID:sinacloud,項目名稱:sinacloud-sdk-java,代碼行數:27,代碼來源:HttpUtils.java

示例8: delete

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
public static Source delete(CloseableHttpClient client, Map<String, String> headers, String url, String encode, List<NameValuePair> pairs) {
	if(null == client){
		if(url.contains("https://")){
			client = defaultSSLClient();
		}else{
			client =  defaultClient();
		}
	}
	Source result = new Source();
	if (null != pairs) {
		String params = URLEncodedUtils.format(pairs,encode);
		if (url.contains("?")) {
			url += "&" + params;
		} else {
			url += "?" + params;
		}
	}
	HttpDelete method = new HttpDelete(url);
	setHeader(method, headers);
	result = exe(client, method, encode);
	return result;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:23,代碼來源:HttpClientUtil.java

示例9: getQueryString

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
 * Parses the request for the queryString
 *
 * @return URL Encoded String of Parameter Value Pair
 */
public static String getQueryString() {
  List<BasicNameValuePair> fields = new LinkedList<BasicNameValuePair>();
  final Set<Map.Entry<String, String[]>> entries = request().queryString().entrySet();
  for (Map.Entry<String, String[]> entry : entries) {
    final String key = entry.getKey();
    final String value = entry.getValue()[0];
    if (!key.equals(PAGE)) {
      fields.add(new BasicNameValuePair(key, value));
    }
  }
  if (fields.isEmpty()) {
    return null;
  } else {
    return URLEncodedUtils.format(fields, "utf-8");
  }
}
 
開發者ID:linkedin,項目名稱:dr-elephant,代碼行數:22,代碼來源:Application.java

示例10: getAuthorizeUrl

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
 * get authorize url
 *
 * @param responseType code or token
 * @param clientId
 * @param redirectUri
 * @param scope
 * @param state
 * @return
 */
public static String getAuthorizeUrl(
        ResponseType responseType, long clientId, String redirectUri, String scope, String state) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(CLIENT_ID, String.valueOf(clientId)));
    params.add(new BasicNameValuePair(RESPONSE_TYPE, responseType.getType()));
    if (StringUtils.isNotEmpty(scope)) {
        params.add(new BasicNameValuePair(SCOPE, scope));
    }
    if (StringUtils.isNotEmpty(state)) {
        params.add(new BasicNameValuePair(STATE, state));
    }
    params.add(new BasicNameValuePair(REDIRECT_URI, redirectUri));
    String query = URLEncodedUtils.format(params, GlobalConstants.DEFAULT_CHARSET);
    return String.format("%s?%s", getAuthorizeUrl(), query);
}
 
開發者ID:xiaomi-passport,項目名稱:oauth-java-sdk,代碼行數:26,代碼來源:AuthorizeUrlUtils.java

示例11: doPostBadAttachmentWithContent

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
protected void doPostBadAttachmentWithContent(String assetId,
                                              String name,
                                              Attachment attachment,
                                              byte[] content,
                                              ContentType contentType,
                                              int expectedRC,
                                              String expectedMessage)
        throws ClientProtocolException, IOException, InvalidJsonAssetException {

    List<NameValuePair> qparams = new ArrayList<>();
    qparams.add(new BasicNameValuePair("name", name));
    String url = "/assets/" + assetId + "/attachments?"
                 + URLEncodedUtils.format(qparams, "UTF-8");

    String response = doPostMultipart(url,
                                      name,
                                      attachment.toJson(),
                                      content,
                                      contentType,
                                      expectedRC);

    if (expectedMessage != null) {
        String errorMessage = parseErrorObject(response);
        assertEquals("Unexpected message from server", expectedMessage, errorMessage);
    }
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:27,代碼來源:RepositoryContext.java

示例12: getContent

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
 * Encodes the request as a multipart message for sending to the server.
 * 
 * @return MultipartEntity suitable for transmission in an HTTP request.
 */
@Override
public HttpEntity getContent() {
  
  // Add a part with as a form
  List<NameValuePair> parms = new ArrayList<NameValuePair>();
  getHttpQueryParms(parms);
  String parmsText = URLEncodedUtils.format(parms, Consts.UTF_8);
  
  MultipartEntityBuilder builder =  MultipartEntityBuilder.create()
      .addTextBody("parms", parmsText, ContentType.create("application/x-www-form-urlencoded", Consts.UTF_8));
  
  for (FormBodyPart part: attachments)
    builder.addPart(part.getName(), part.getBody());
   
   return builder.build();
}
 
開發者ID:Idilia,項目名稱:idilia-java-sdk,代碼行數:22,代碼來源:DisambiguateRequest.java

示例13: getPrivateRequestHeader

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
private List<Header> getPrivateRequestHeader(String path, List<NameValuePair> query) throws BitbankException {
    long nonce = System.currentTimeMillis();
    String queryString = URLEncodedUtils.format(query, "utf-8");
    if(query.size() > 0) queryString = "?" + queryString;
    String message = String.valueOf(nonce) + path + queryString;
    return makePrivateRequestHeader(nonce, createSign(message));
}
 
開發者ID:bitbankinc,項目名稱:java-bitbankcc,代碼行數:8,代碼來源:Bitbankcc.java

示例14: queryStringNv

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
@Nullable
private String queryStringNv(@Nullable List<NameValuePair> params)
{
	if( params == null )
	{
		return null;
	}
	return URLEncodedUtils.format(params, Constants.UTF8);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:10,代碼來源:HttpServiceImpl.java

示例15: queryString

import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
 * Turns a list of NameValuePair into a query string. e.g
 * param1=val1&param2=val2
 * 
 * @param params
 * @return
 */
public String queryString(List<NameValuePair> params)
{
	if( params == null )
	{
		return null;
	}
	return URLEncodedUtils.format(params, "UTF-8");
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:16,代碼來源:AbstractRestApiTest.java


注:本文中的org.apache.http.client.utils.URLEncodedUtils.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。