Tabnine Logo
URLEncoder
Code IndexAdd Tabnine to your IDE (free)

How to use
URLEncoder
in
java.net

Best Java code snippets using java.net.URLEncoder (Showing top 20 results out of 31,905)

Refine searchRefine arrow

  • URL
  • URLConnection
  • InputStreamReader
  • BufferedReader
  • HttpURLConnection
origin: stackoverflow.com

URL url = new URL("http://example.net/new-message.php");
Map<String,Object> params = new LinkedHashMap<>();
params.put("name", "Freddie the Fish");
for (Map.Entry<String,Object> param : params.entrySet()) {
  if (postData.length() != 0) postData.append('&');
  postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
  postData.append('=');
  postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
origin: libgdx/libgdx

    || (ch >= '0' && ch <= '9') || " .-*_".indexOf(ch) > -1) {
  if (start >= 0) {
    convert(s.substring(start, i), buf, enc);
    start = -1;
convert(s.substring(start, s.length()), buf, enc);
origin: stackoverflow.com

 public static void main(String[] args) throws Exception {
  String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
  String search = "stackoverflow";
  String charset = "UTF-8";

  URL url = new URL(google + URLEncoder.encode(search, charset));
  Reader reader = new InputStreamReader(url.openStream(), charset);
  GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);

  // Show title and URL of 1st result.
  System.out.println(results.getResponseData().getResults().get(0).getTitle());
  System.out.println(results.getResponseData().getResults().get(0).getUrl());
}
origin: stackoverflow.com

BufferedReader rd = new BufferedReader(new InputStreamReader(
    response.getEntity().getContent()));
while ((line = rd.readLine()) != null) {
  Log.e("HttpResponse", line);
  if (line.startsWith("Auth=")) {
    .append(URLEncoder.encode("Fax Sent ... Test Push Notification ....", UTF8));
URL url = new URL("https://android.clients.google.com/c2dm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("Content-Length",
out.close();
int responseCode = conn.getResponseCode();
String responseLine = new BufferedReader(new InputStreamReader(
    conn.getInputStream())).readLine();
origin: osmandapp/Osmand

boolean firstPrm =!urlText.contains("?");
for (String key : additionalMapData.keySet()) {
  urlText += (firstPrm ? "?" : "&") + key + "=" + URLEncoder.encode(additionalMapData.get(key), "UTF-8");
  firstPrm = false;
url = new URL(urlText);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
if(userNamePassword != null) {
  conn.setRequestProperty("Authorization", "Basic " + Base64.encode(userNamePassword)); //$NON-NLS-1$ //$NON-NLS-2$
StringBuilder responseBody = new StringBuilder();
if (is != null) {
  BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); //$NON-NLS-1$
  String s;
  boolean first = true;
  while ((s = in.readLine()) != null) {
    if(first){
      first = false;
origin: apache/cloudstack

trafficSentinel = new URL(_url + "/inmsf/Query");
String postData = "script="+URLEncoder.encode(getScript(cmd.getPublicIps(), cmd.getStart(), cmd.getEnd()), "UTF-8")+"&authenticate=basic&resultFormat=txt";
HttpURLConnection con = (HttpURLConnection) trafficSentinel.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Length", String.valueOf(postData.length()));
con.setDoOutput(true);
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
  in.close();
origin: stackoverflow.com

      for (NameValuePair p : params)
        String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(),"UTF-8");
        if (combinedParams.length() > 1)
          combinedParams += "&" + paramString;
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try
  while ((line = reader.readLine()) != null)
origin: stackoverflow.com

  URL url = new URL(AUTH_URL);
  String source = CLIENT_ID;
  userName = URLEncoder.encode(userName, "UTF-8");
  password = URLEncoder.encode(password, "UTF-8");
  OutputStreamWriter outStreamWriter = new OutputStreamWriter(urlConnection.getOutputStream());
  outStreamWriter.write(loginData);
  outStreamWriter.close();
  int responseCode = urlConnection.getResponseCode();
    Log.d(TAG, "Got an error response : " + responseCode + " "  + urlConnection.getResponseMessage());
    throw new IOException(urlConnection.getResponseMessage());
    while ((line = br.readLine()) != null) {
FileInputStream fileStream = new FileInputStream(file);
URL url = new URL(uploadUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", String.format("GoogleLogin auth=\"%s\"",  clientLoginToken));
origin: Mavamaarten/vk_music_android

private String getAlbumArtUrlString(String query) throws IOException, NoAlbumArtFoundException {
  URL url;
  url = new URL("http://www.bing.com/?q=" + URLEncoder.encode(query, "UTF-8") + "&scope=images&qft=+filterui:aspect-square");
  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  urlConnection.setRequestProperty("User-Agent", "Googlebot/2.1 (+http://www.google.com/bot.html)");
  urlConnection.setRequestMethod("GET");
  BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  StringBuilder result = new StringBuilder();
  String inputLine;
  while ((inputLine = in.readLine()) != null) {
    result.append(inputLine);
  }
  return ParseImageUrlFromResult(result.toString());
}
origin: openmrs/openmrs-core

  data.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
  data.append("=");
  data.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length", String.valueOf(data.length()));
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
rd = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = rd.readLine()) != null) {
  response = String.format("%s%s%n", response, line);
    rd.close();
origin: stackoverflow.com

  sb.append("?sensor=false&key=" + API_KEY);
  sb.append("&input=" + URLEncoder.encode(input, "utf8"));
  URL url = new URL(sb.toString());
  conn = (HttpURLConnection) url.openConnection();
  InputStreamReader in = new InputStreamReader(conn.getInputStream());
} finally {
  if (conn != null) {
    conn.disconnect();
origin: stackoverflow.com

 String rawData = "id=10";
String type = "application/x-www-form-urlencoded";
String encodedData = URLEncoder.encode( rawData ); 
URL u = new URL("http://www.example.com/page.php");
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length", String.valueOf(encodedData.length()));
OutputStream os = conn.getOutputStream();
os.write(encodedData.getBytes());
origin: stackoverflow.com

 try {
  String base = "http://www.somethingxxxxx.com/";
  String toEncode = "adiós";
  String myEncodedUrl = base + URLEncoder.encode( toEncode, "UTF-8" );
  URLConnection yc = new URL(myEncodedUrl).openConnection();
  BufferedReader in = new BufferedReader(new InputStreamReader(
                      yc.getInputStream()));
} catch ( UnsupportedEncodingException exc ) {
  exc.printStackTrace();
} catch ( IOException exc ) {
  exc.printStackTrace();
}
origin: stackoverflow.com

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
  else
    query.append("&");
  query.append(URLEncoder.encode(pair.getName(), "UTF-8"));
  query.append("=");
  query.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
  if ((avatarName = pair.getName()).equals("avatar")) {
    avatarPath = pair.getValue();
dataOutputStream.close();
String responseMessage = connection.getResponseMessage();
Log.d(TAG, responseMessage);
InputStream in = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
connection.disconnect();
Log.d(TAG, response.toString());
return response.toString();
origin: languagetool-org/languagetool

private URL buildURLForExplanation(String original) {
 try {
  String query = URLEncoder.encode("convert " + original + " to metric", "utf-8");
  return new URL("http://www.wolframalpha.com/input/?i=" + query);
 } catch (Exception e) {
  return null;
 }
}
origin: loklak/loklak_server

protected void process(HttpServletRequest request, HttpServletResponse response, Query post) throws ServletException, IOException {
  DAO.log("MARKDOWN-TEXT: " + URLEncoder.encode(text, "UTF-8"));
  int padding = post.get("padding", 3);
  boolean uppercase = post.get("uppercase", true);
  BufferedReader rdr = new BufferedReader(new StringReader(text));
  StringBuilder sb = new StringBuilder();
  int width = 0;
  int linecount = 0;
  for (String line = rdr.readLine(); line != null; line = rdr.readLine()) {
    String[] sublines = line.split("\n");
    for (String subline: sublines) {
origin: frohoff/ysoserial

URL u = new URL(args[ 0 ]);
URLConnection c = u.openConnection();
if ( ! ( c instanceof HttpURLConnection ) ) {
  throw new IllegalArgumentException("Not a HTTP url");
hc.setDoOutput(true);
hc.setRequestMethod("POST");
hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = hc.getOutputStream();
oos.close();
byte[] data = bos.toByteArray();
String requestBody = "javax.faces.ViewState=" + URLEncoder.encode(Base64.encodeBase64String(data), "US-ASCII");
os.write(requestBody.getBytes("US-ASCII"));
os.close();
origin: stackoverflow.com

byte[] postData = URLEncoder.encode( json.toString(), "UTF-8" ).getBytes();
   URL url = new URL( Configuration.loggingURL );
   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setRequestMethod("POST");
   //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
   conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
   conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
   conn.setUseCaches(false);
   DataOutputStream out = new DataOutputStream ( conn.getOutputStream () );
   out.write(postData);
   out.flush();
   out.close();
   conn.disconnect();
origin: stackoverflow.com

 String charset = "UTF-8";
String query = String.format("include=%s", URLEncoder.encode("game", charset));
URL myURL = new URL(serviceURL+"?"+query);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("X-Parse-Application-Id", "");
myURLConnection.setRequestProperty("X-Parse-REST-API-Key", "");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
myURLConnection.connect();
origin: neo4j/neo4j

void ping() throws IOException
{
  pingCount++;
  Map<String, String> usageDataMap = collector.getUdcParams();
  StringBuilder uri = new StringBuilder( "http://" + address + "/" + "?" );
  for ( Map.Entry<String,String> entry : usageDataMap.entrySet() )
  {
    uri.append( entry.getKey() );
    uri.append( "=" );
    uri.append( URLEncoder.encode( entry.getValue(), StandardCharsets.UTF_8.name() ) );
    uri.append( "+" );
  }
  uri.append( PING + "=" ).append( pingCount );
  URL url = new URL( uri.toString() );
  URLConnection con = url.openConnection();
  con.setDoInput( true );
  con.setDoOutput( false );
  con.setUseCaches( false );
  con.connect();
  con.getInputStream().close();
}
java.netURLEncoder

Javadoc

This class is used to encode a string using the format required by application/x-www-form-urlencoded MIME content type.

All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and characters '.', '-', '*', '_' are converted into their hexadecimal value prepended by '%'. For example: '#' -> %23. In addition, spaces are substituted by '+'.

Most used methods

  • encode
  • convert
  • <init>

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getApplicationContext (Context)
  • getExternalFilesDir (Context)
  • findViewById (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JButton (javax.swing)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now