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"));
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()); }
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();
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;
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();
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)
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));
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()); }
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();
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();
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());
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(); }
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();
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) {
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();
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();
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();
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(); }