本文整理汇总了Java中org.apache.http.client.utils.URLEncodedUtils类的典型用法代码示例。如果您正苦于以下问题:Java URLEncodedUtils类的具体用法?Java URLEncodedUtils怎么用?Java URLEncodedUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URLEncodedUtils类属于org.apache.http.client.utils包,在下文中一共展示了URLEncodedUtils类的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: decodeExtras
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
private Map<String, String> decodeExtras(String extras) {
Map<String, String> results = new HashMap<String, String>();
try {
URI rawExtras = new URI("?" + extras);
List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
for (NameValuePair item : extraList) {
String name = item.getName();
int i = 0;
while (results.containsKey(name)) {
name = item.getName() + ++i;
}
results.put(name, item.getValue());
}
} catch (URISyntaxException e) {
Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
}
return results;
}
示例3: 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;
}
示例4: getExpectedParams
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
/**
* Get list of expected query parameters.
*
* @param pageUrl page URL annotation
* @param expectUri expected landing page URI
* @return list of expected query parameters
*/
private static List<NameValuePair> getExpectedParams(PageUrl pageUrl, URI expectUri) {
List<NameValuePair> expectParams = new ArrayList<>();
String[] params = pageUrl.params();
if (params.length > 0) {
for (String param : params) {
String[] nameValueBits = param.split("=");
if (nameValueBits.length == 2) {
String name = nameValueBits[0].trim();
String value = nameValueBits[1].trim();
expectParams.add(new BasicNameValuePair(name, value));
} else {
throw new IllegalArgumentException("Format of PageUrl parameter '" + param
+ "' does not conform to template [name]=[pattern]");
}
}
} else if (expectUri != null) {
expectParams = URLEncodedUtils.parse(expectUri, "UTF-8");
}
return expectParams;
}
示例5: getParameter
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
/**
* Extract a query string parameter without triggering http parameters
* processing by the servlet container.
*
* @param request the request
* @param name the parameter to get the value.
* @return the parameter value, or <code>NULL</code> if the parameter is not
* defined.
* @throws IOException thrown if there was an error parsing the query string.
*/
public static String getParameter(HttpServletRequest request, String name)
throws IOException {
List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(),
UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (name.equals(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}
示例6: getDoAs
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
@VisibleForTesting
static String getDoAs(HttpServletRequest request) {
List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(),
UTF8_CHARSET);
if (list != null) {
for (NameValuePair nv : list) {
if (DelegationTokenAuthenticatedURL.DO_AS.
equalsIgnoreCase(nv.getName())) {
return nv.getValue();
}
}
}
return null;
}
示例7: getCourseListings
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
@Override
public void getCourseListings() throws MalformedURLException {
// From the home page, retrieve all links to current courses
// We also need to remove any links present in the course data block to prevent announcements
// from being interpreted as classes
WebElement simpleTable = action.waitForElement(By.xpath("//*[@id=\"_3_1termCourses_noterm\"]/ul"));
List<WebElement> links = simpleTable.findElements(By.tagName("a"));
List<WebElement> courseDataBlocks = simpleTable.findElements(By.className("courseDataBlock"));
for (WebElement we : courseDataBlocks) {
links.removeAll(we.findElements(By.tagName("a")));
}
CourseListing[] cls = new CourseListing[links.size()];
for (int i = 0; i < links.size(); i++) {
cls[i] = new CourseListing();
cls[i].course_name = links.get(i).getText();
String course_url = links.get(i).getAttribute("href");
cls[i].base_url = course_url;
try {
List<NameValuePair> params;
params = URLEncodedUtils.parse(new URI(course_url), java.nio.charset.StandardCharsets.UTF_8);
//Find course_id str
for(NameValuePair nvp : params)
{
if(nvp.getName().equals("course_id"))
{
cls[i].course_id = nvp.getValue();
break;
}
}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
addSubGrabber(cls);
}
示例8: getProperty
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
/**
* MSSQL driver do not return password, so we need to parse it manually
* @param property
* @param connectionString
* @return
*/
protected static String getProperty(String property, String connectionString) {
String ret = null;
if (property != null && !property.isEmpty() && connectionString != null && !connectionString.isEmpty()) {
for (NameValuePair param : URLEncodedUtils.parse(connectionString, StandardCharsets.UTF_8, SEPARATORS)) {
if(property.equals(param.getName())){
ret = param.getValue();
break;
}
}
}
return ret;
}
示例9: doMyResourcesSearch
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
private JsonNode doMyResourcesSearch(String query, String subsearch, Map<?, ?> otherParams, String token)
throws Exception
{
List<NameValuePair> params = Lists.newArrayList();
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/myresources/" + subsearch + "?" + paramString);
HttpResponse response = execute(get, false, token);
return mapper.readTree(response.getEntity().getContent());
}
示例10: 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());
}
示例11: doNotificationsSearch
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
private JsonNode doNotificationsSearch(String query, String subsearch, Map<?, ?> otherParams, String token)
throws Exception
{
List<NameValuePair> params = Lists.newArrayList();
if( query != null )
{
params.add(new BasicNameValuePair("q", query));
}
if( subsearch != null )
{
params.add(new BasicNameValuePair("type", subsearch));
}
for( Entry<?, ?> entry : otherParams.entrySet() )
{
params.add(new BasicNameValuePair(entry.getKey().toString(), entry.getValue().toString()));
}
String paramString = URLEncodedUtils.format(params, "UTF-8");
HttpGet get = new HttpGet(context.getBaseUrl() + "api/notification?" + paramString);
HttpResponse response = execute(get, false, token);
return mapper.readTree(response.getEntity().getContent());
}
示例12: getMacAccessTokenSignatureString
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
protected static String getMacAccessTokenSignatureString(String nonce, String method, String
host, String uriPath, String query, String macKey, String macAlgorithm) throws
InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
if ("HmacSHA1".equalsIgnoreCase(macAlgorithm)) {
StringBuilder joined = new StringBuilder("");
joined.append(new StringBuilder(String.valueOf(nonce)).append("\n").toString());
joined.append(method.toUpperCase() + "\n");
joined.append(new StringBuilder(String.valueOf(host)).append("\n").toString());
joined.append(new StringBuilder(String.valueOf(uriPath)).append("\n").toString());
if (!TextUtils.isEmpty(query)) {
StringBuffer sb = new StringBuffer();
List<NameValuePair> paramList = new ArrayList();
URLEncodedUtils.parse(paramList, new Scanner(query), "UTF-8");
Collections.sort(paramList, new Comparator<NameValuePair>() {
public int compare(NameValuePair p1, NameValuePair p2) {
return p1.getName().compareTo(p2.getName());
}
});
sb.append(URLEncodedUtils.format(paramList, "UTF-8"));
joined.append(sb.toString() + "\n");
}
return encodeSign(encryptHMACSha1(joined.toString().getBytes("UTF-8"), macKey
.getBytes("UTF-8")));
}
throw new NoSuchAlgorithmException("error mac algorithm : " + macAlgorithm);
}
示例13: parseUrl
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
private Bundle parseUrl(String url) {
Bundle b = new Bundle();
if (url != null) {
try {
for (NameValuePair pair : URLEncodedUtils.parse(new URI(url), "UTF-8")) {
if (!(TextUtils.isEmpty(pair.getName()) || TextUtils.isEmpty(pair.getValue())
)) {
b.putString(pair.getName(), pair.getValue());
}
}
} catch (URISyntaxException e) {
Log.e("openauth", e.getMessage());
}
}
return b;
}
示例14: doHttpGet
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
public static String doHttpGet(Context context, String path, long clientId, String
accessToken, String macKey, String macAlgorithm) throws XMAuthericationException {
List<NameValuePair> params = new ArrayList();
params.add(new BasicNameValuePair("clientId", String.valueOf(clientId)));
params.add(new BasicNameValuePair("token", accessToken));
String nonce = AuthorizeHelper.generateNonce();
try {
return Network.downloadXml(context, new URL(AuthorizeHelper.generateUrl(HTTP_PROTOCOL
+ HOST + path, params)), null, null, AuthorizeHelper.buildMacRequestHead
(accessToken, nonce, AuthorizeHelper.getMacAccessTokenSignatureString(nonce,
METHOD_GET, HOST, path, URLEncodedUtils.format(params, "UTF-8"),
macKey, macAlgorithm)), null);
} catch (Throwable e) {
throw new XMAuthericationException(e);
} catch (Throwable e2) {
throw new XMAuthericationException(e2);
} catch (Throwable e22) {
throw new XMAuthericationException(e22);
} catch (Throwable e222) {
throw new XMAuthericationException(e222);
}
}
示例15: a
import org.apache.http.client.utils.URLEncodedUtils; //导入依赖的package包/类
public final byte[] a() {
try {
List arrayList = new ArrayList();
if (this.d != null) {
arrayList.add(new BasicNameValuePair("extParam", f.a(this.d)));
}
arrayList.add(new BasicNameValuePair("operationType", this.a));
arrayList.add(new BasicNameValuePair("id", this.c));
new StringBuilder("mParams is:").append(this.b);
arrayList.add(new BasicNameValuePair("requestData", this.b == null ? "[]" : f.a(this.b)));
return URLEncodedUtils.format(arrayList, Constants.UTF_8).getBytes();
} catch (Throwable e) {
Throwable th = e;
throw new RpcException(Integer.valueOf(9), new StringBuilder("request =").append(this.b).append(":").append(th).toString() == null ? "" : th.getMessage(), th);
}
}