List of usage examples for java.net URLEncoder encode
public static String encode(String s, Charset charset)
From source file:conroller.TankController.java
public static ArrayList<TankModel> searchTank(String tankN) throws IOException, JSONException { String data = URLEncoder.encode("tankName", "UTF-8") + "=" + URLEncoder.encode(tankN, "UTF-8"); phpConnection.setConnection(//from w w w . j av a 2s.c o m "http://itmahaweliauthority.net23.net/MahaweliAuthority/TankPHPfiles/SearchTankByTankId.php"); phpConnection.sendData(data); String response = phpConnection.readData(); if (response.equals("notExist")) { return null; } else { return getJSONData(response); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.listing.ListingControllerWebUtils.java
public static synchronized String formatVClassLinks(List<VClass> vList) { String linksStr = ""; if (vList != null) { int count = 0; for (Object obj : vList) { try { if (count > 0) linksStr += " | "; VClass vclass = (VClass) obj; try { linksStr += "<a href=\"vclassEdit?uri=" + URLEncoder.encode(vclass.getURI(), "UTF-8") + "\">" + vclass.getName() + "</a>"; } catch (UnsupportedEncodingException e) { linksStr += vclass.getName(); }//from w w w.j a va 2 s .co m ++count; } catch (Exception e) { if (obj == null) { log.error(ListingControllerWebUtils.class.getName() + " could not format null VClass"); } } } } return linksStr; }
From source file:com.memetix.gun4j.expand.UrlExpander.java
public static String expand(final String shortUrl) throws Exception { if (shortUrl != null) { final StringBuilder sb = new StringBuilder(); sb.append(PARAM_NAME);/* w w w . j ava 2 s. c o m*/ sb.append(EQUALS); sb.append(URLEncoder.encode(shortUrl, ENCODING)); Map<String, String> results = parseResponse(post(SERVICE_URL, sb.toString())); if (results.containsKey(shortUrl)) return results.get(shortUrl); else return shortUrl.toString(); } else { return null; } }
From source file:com.system.util.encode.EncodeUtils.java
/** * URL ?, EncodeUTF-8. /*from w w w . j ava2s . c om*/ */ public static String urlEncode(String input) { try { return URLEncoder.encode(input, EncodeUtil.ENCODE); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Unsupported Encoding Exception", e); } }
From source file:com.github.thorqin.webapi.oauth2.OAuthServer.java
public static String makeAuthorizationSuccessUri(String redirectionUri, String code, String state) throws IOException { StringBuilder result = new StringBuilder(redirectionUri); if (redirectionUri.contains("?")) result.append("&code="); else//from www .ja v a 2 s. co m result.append("?code="); result.append(URLEncoder.encode(code, "utf-8")); if (state != null) result.append("&state=").append(URLEncoder.encode(state, "utf-8")); return result.toString(); }
From source file:crow.weibo.util.WeiboUtil.java
/** * ??/* w w w . j a v a 2 s. c o m*/ * * @param value * @return */ public static String encode(String s) { if (s == null) { return ""; } try { return URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~") .replace("#", "%23"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.acra.util.HttpUtils.java
/** * Send an HTTP(s) request with POST parameters. * /* w ww . ja v a 2 s. c o m*/ * @param parameters * @param url * @throws ClientProtocolException * @throws IOException */ public static void doPost(Map<?, ?> parameters, URL url, String login, String password) throws ClientProtocolException, IOException { // Construct data final StringBuilder dataBfr = new StringBuilder(); for (final Object key : parameters.keySet()) { if (dataBfr.length() != 0) { dataBfr.append('&'); } Object value = parameters.get(key); if (value == null) { value = ""; } dataBfr.append(URLEncoder.encode(key.toString(), "UTF-8")).append('=') .append(URLEncoder.encode(value.toString(), "UTF-8")); } final HttpRequest req = new HttpRequest(isNull(login) ? null : login, isNull(password) ? null : password); req.sendPost(url.toString(), dataBfr.toString()); }
From source file:io.wcm.caravan.io.http.impl.CaravanHttpHelper.java
/** * @param token Token to encode//from w w w .ja va2 s . c o m * @return Encoded token */ public static String urlEncode(final Object token) { try { return URLEncoder.encode(String.valueOf(token), Charsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:codes.thischwa.c5c.util.StringUtils.java
public static final String encode(final String str) { try {/* ww w . j a v a2 s . c o m*/ return URLEncoder.encode(str, PropertiesLoader.getDefaultEncoding()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.sniper.springmvc.utils.CookieUtils.java
/** * Cookie//from ww w. j a v a 2 s .co m * * @param name * ?? * @param value * * @param maxAge * ?? */ public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) { Cookie cookie = new Cookie(name, null); if (StringUtils.isNotBlank(SpringContextHolder.getApplicationContext().getApplicationName())) { cookie.setPath(SpringContextHolder.getApplicationContext().getApplicationName()); } else { cookie.setPath("/"); } cookie.setMaxAge(maxAge); try { cookie.setValue(URLEncoder.encode(value, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } response.addCookie(cookie); }