URL url = new URL(user_image_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is);
public URLConnection getURLConnection() throws IOException { if (urlConnection == null) { if (proxy != null) { urlConnection = url.openConnection(proxy); } else { urlConnection = url.openConnection(); } urlConnection.setDoInput(false); urlConnection.setDoOutput(false); if (getMode().startsWith("r") || getMode().startsWith("w") || getMode().startsWith("a")) { urlConnection.setDoInput(true); } if (getMode().startsWith("w") || getMode().startsWith("a")) { urlConnection.setDoOutput(true); } } return urlConnection; }
URL myURL = new URL(serviceURL); HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection(); String userCredentials = "username:password"; String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes())); myURLConnection.setRequestProperty ("Authorization", basicAuth); myURLConnection.setRequestMethod("POST"); myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length); myURLConnection.setRequestProperty("Content-Language", "en-US"); myURLConnection.setUseCaches(false); myURLConnection.setDoInput(true); myURLConnection.setDoOutput(true);
public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { // Log exception return null; } }
URL url = new URL("http://yoururl.com"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); Uri.Builder builder = new Uri.Builder() .appendQueryParameter("firstParam", paramValue1) .appendQueryParameter("secondParam", paramValue2) .appendQueryParameter("thirdParam", paramValue3); String query = builder.build().getEncodedQuery(); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); writer.write(query); writer.flush(); writer.close(); os.close(); conn.connect();
public Bitmap getBitmapFromURL(String strURL) { try { URL url = new URL(strURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } }
public Bitmap getBitmapFromURL(String strURL) { try { URL url = new URL(strURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } }
String response = ""; try { url = new URL(requestURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(15000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line=br.readLine()) != null) { response+=line;
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(); }
public static Bitmap getBitmapFromURL(String src) { try { Log.e("src",src); URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); Log.e("Bitmap","returned"); return myBitmap; } catch (IOException e) { e.printStackTrace(); Log.e("Exception",e.getMessage()); return null; } }
public Bitmap getBitmapFromURL(String src) { try { java.net.URL url = new java.net.URL(src); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } }
/** * Opens an InputStream for the given URL. */ /*package*/ static InputStream openUrl(String url) throws IOException { try { URLConnection urlConnection = new URL(url).openConnection(); urlConnection.setConnectTimeout(TIMEOUT); urlConnection.setReadTimeout(TIMEOUT); urlConnection.setDoInput(true); urlConnection.setDoOutput(false); return urlConnection.getInputStream(); } catch (Exception e) { IOException ioe = new IOException("Couldn't open " + url); ioe.initCause(e); throw ioe; } }
URL url; URLConnection urlConn; DataOutputStream printout; DataInputStream input; url = new URL (getCodeBase().toString() + "env.tcgi"); urlConn = url.openConnection(); urlConn.setDoInput (true); urlConn.setDoOutput (true); urlConn.setUseCaches (false); urlConn.setRequestProperty("Content-Type","application/json"); urlConn.setRequestProperty("Host", "android.schoolportal.gr"); urlConn.connect(); //Create JSONObject here JSONObject jsonParam = new JSONObject(); jsonParam.put("ID", "25"); jsonParam.put("description", "Real"); jsonParam.put("enable", "true");
@Signature public static URLConnection create(String url, @Nullable Proxy proxy) throws IOException { URL _url = new URL(url); URLConnection urlConnection = proxy == null ? _url.openConnection() : _url.openConnection(proxy); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); if (urlConnection instanceof HttpURLConnection) { HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; httpURLConnection.setRequestMethod("GET"); } return urlConnection; }
URL url = new URL("http","www.google.com"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); urlc.setAllowUserInteraction( false ); urlc.setDoInput( true ); urlc.setDoOutput( false ); urlc.setUseCaches( true ); urlc.setRequestMethod("GET"); urlc.connect(); // check you have received an status code 200 to indicate OK // get the encoding from the Content-Type header BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String line = null; while((line = in.readLine()) != null) { System.out.println(line); } // close sockets, handle errors, etc.
String response = ""; try { url = new URL(requestURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(15000); conn.setConnectTimeout(15000); conn.setRequestMethod("GET"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line=br.readLine()) != null) { response+=line;
@Override protected Void doInBackground(Void... params) { try { URL myFileUrl = new URL("http://sposter.smartag.my/images/chicken_soup.jpg"); HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); downloadBitmap = BitmapFactory.decodeStream(is); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override onPostExecute() { ImageView image = (ImageView) findViewById(R.id.imview); image.setImageBitmap(downloadBitmap); }
public static String sendPostRequest(String requestUrl, String payload) { try { URL url = new URL(requestUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); writer.write(payload); writer.close(); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer jsonString = new StringBuffer(); String line; while ((line = br.readLine()) != null) { jsonString.append(line); } br.close(); connection.disconnect(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } return jsonString.toString(); }
private StringBuffer request(String urlString) { // TODO Auto-generated method stub StringBuffer chaine = new StringBuffer(""); try{ URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestProperty("User-Agent", ""); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.connect(); InputStream inputStream = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); String line = ""; while ((line = rd.readLine()) != null) { chaine.append(line); } } catch (IOException e) { // Writing exception to log e.printStackTrace(); } return chaine; }
protected Bitmap doInBackground(Void... params) { try { URL urlConnection = new URL(url); HttpURLConnection connection = (HttpURLConnection) urlConnection .openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap;