本文整理匯總了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");
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
示例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);
}
示例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);
}
}
示例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();
}
示例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));
}
示例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);
}
示例15: queryString
import org.apache.http.client.utils.URLEncodedUtils; //導入方法依賴的package包/類
/**
* Turns a list of NameValuePair into a query string. e.g
* param1=val1¶m2=val2
*
* @param params
* @return
*/
public String queryString(List<NameValuePair> params)
{
if( params == null )
{
return null;
}
return URLEncodedUtils.format(params, "UTF-8");
}