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();
/** * Builds the URL used to query Github. * * @param githubSearchQuery The keyword that will be queried for. * @return The URL to use to query the weather server. */ public static URL buildUrl(String githubSearchQuery) { Uri builtUri = Uri.parse(GITHUB_BASE_URL).buildUpon() .appendQueryParameter(PARAM_QUERY, githubSearchQuery) .appendQueryParameter(PARAM_SORT, sortBy) .build(); URL url = null; try { url = new URL(builtUri.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } return url; }
public String syncURL() { // Allow user to specify custom sync server SharedPreferences userPreferences = AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance()); if (userPreferences!= null && userPreferences.getBoolean("useCustomSyncServer", false)) { Uri syncBase = Uri.parse(userPreferences.getString("syncBaseUrl", Consts.SYNC_BASE)); return syncBase.buildUpon().appendPath("sync").toString() + "/"; } // Usual case return Consts.SYNC_BASE + "sync/"; } }
URL url = new URL("your_api_url"); 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(); builder.appendQueryParameter("data" , "json_value"); String query = builder.build().getEncodedQuery(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8")); writer.write(query); writer.flush(); writer.close(); int response = conn.getResponseCode(); if(response == HttpURLConnection.HTTP_OK) { InputStream bis = new BufferedInputStream(conn.getInputStream()); //bis is your json do whatever you want with it } conn.disconnect();
String link = "http://cvbenim.com/api/v1/isveren/uyeliktamamla?token="+token; URL url = new URL(link); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestProperty("User-Agent", ""); connection.setRequestMethod("POST"); connection.setDoInput(true); Uri.Builder builder = new Uri.Builder() .appendQueryParameter("firma_adi","SomeName") .appendQueryParameter("sektor", "1") .appendQueryParameter("sehir", "2") .appendQueryParameter("ilce", "3") .appendQueryParameter("semt","4") .appendQueryParameter("adres","SomePlace") .appendQueryParameter("telefon","02122342111") .appendQueryParameter("email", "someName@gmail.com") .appendQueryParameter("web","dogu.com"); String query = builder.build().getEncodedQuery(); OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(query); writer.flush(); connection.connect();
HttpURLConnection connection = null; URL url = new URL("http://sridharweb2.esy.es/gift_voucher.php"); connection = (HttpURLConnection)url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("GET"); connection.setUseCaches(false); connection.setConnectTimeout(720000000); connection.setReadTimeout(72000000); connection.connect(); Uri.Builder builder = new Uri.Builder() .appendQueryParameter("customer_id", customer_id) String data = builder.build().getEncodedQuery(); OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream()); output.write(data); output.flush(); output.close(); connection.disconnect();
URL url = new URL("http://example.sitedemo.service.php"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); Uri.Builder builder = new Uri.Builder().appendQueryParameter("username", "maven") .appendQueryParameter("password", "123"); 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(); InputStream in = new BufferedInputStream(conn.getInputStream()); response = IOUtils.toString(in, "UTF-8");
try { URL url = new URL("http://example.com"); httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setConnectTimeout(15000); Uri.Builder builder = new Uri.Builder().appendQueryParameter("firstParameter", firsParametersValue).appendQueryParameter("secondParameter", secondParametersValue) String query = builder.build().getEncodedQuery(); OutputStream outputStream = httpURLConnection.getOutputStream(); BufferedWriter bufWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); bufWriter.write(query); bufWriter.flush(); bufWriter.close(); outputStream.close(); if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { StringBuilder response = new StringBuilder(); BufferedReader input = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()), 8192); String strLine = null; while ((strLine = input.readLine()) != null) { httpURLConnection.disconnect();// close connection
String url = "http://xx.xx.xx.xx:5000/models/images/one.json"; URL obj = new URL(url); HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); conn.setRequestMethod("POST"); //build it this way 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();
Uri.Builder builder = new Uri.Builder().appendQueryParameter("param1", value1) .appendQueryParameter("param2", value2); final String query = builder.build().getEncodedQuery(); URL url; HttpURLConnection connection = null; try{ url = new URL("http://www.example.com/directory/"); connection = (HttpURLConnection) url.openConnection(); OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(query); writer.flush(); writer.close(); os.close(); connection.connect(); }
Uri.Builder urlBuilder = new Uri.Builder(); urlBuilder.scheme("http"); urlBuilder.authority("api.openweathermap.org"); urlBuilder.appendEncodedPath("data/2.5/forecast/daily"); urlBuilder.appendQueryParameter("zip", "94043,us"); URL url = new URL(urlBuilder.build().toString());
Uri.Builder builder = new Uri.Builder(); builder.appendQueryParameter("param1", "paramvalue1"); builder.appendQueryParameter("param2", "paramvalue2"); 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(); is = conn.getInputStream();
private void handlePageList(LightHttpResponse response) throws JSONException { if (mPageListResponse == null) { JSONArray reply = new JSONArray(); JSONObject page = new JSONObject(); page.put("type", "app"); page.put("title", makeTitle()); page.put("id", PAGE_ID); page.put("description", ""); page.put("webSocketDebuggerUrl", "ws://" + mInspectorPath); Uri chromeFrontendUrl = new Uri.Builder() .scheme("http") .authority("chrome-devtools-frontend.appspot.com") .appendEncodedPath("serve_rev") .appendEncodedPath(WEBKIT_REV) .appendEncodedPath("devtools.html") .appendQueryParameter("ws", mInspectorPath) .build(); page.put("devtoolsFrontendUrl", chromeFrontendUrl.toString()); reply.put(page); mPageListResponse = LightHttpBody.create(reply.toString(), "application/json"); } setSuccessfulResponse(response, mPageListResponse); }
@Override public String requestCustomSizeUrl(Integer width, Integer height) { if (baseImageUrl != null) { return baseImageUrl .buildUpon() .appendQueryParameter("width", width.toString()) .appendQueryParameter("height", height.toString()) .build() .toString(); } throw new RuntimeException("You have to set the base image url first"); } }
@Nullable public static Uri getUriForProvidedFile(@NonNull Context context, File file, @Nullable String encoding, @Nullable String mimeType) { try { Uri.Builder uriBuilder = FileProvider.getUriForFile(context, AUTHORITY, file).buildUpon(); if (mimeType != null) { uriBuilder.appendQueryParameter("mime_type", mimeType); } if (encoding != null) { uriBuilder.appendQueryParameter("encoding", encoding); } return uriBuilder.build(); } catch (IllegalArgumentException e) { return null; } }
public static Uri getMimeTypeUri(Uri contentUri, String mimeType) { if (!AUTHORITY.equals(contentUri.getAuthority())) { throw new IllegalArgumentException("Can only call this method for URIs within this authority!"); } if (contentUri.getQueryParameter("mime_type") != null) { throw new IllegalArgumentException("Can only call this method for not yet typed URIs!"); } return contentUri.buildUpon().appendQueryParameter("mime_type", mimeType).build(); }
Uri.Builder builder = new Uri.Builder(); builder.scheme("file"); builder.path(myFilePath); Uri uri = builder.build(); File file = new File(uri.getPath()); if (file.exists()) { uris.add(uri); // do whatever you want }
private static Uri getOriginUri(Uri uri) { Uri.Builder b = uri.buildUpon(); b.encodedPath(null); List<String> segments = uri.getPathSegments(); for (int i = 0; i < segments.size() - 1; i++) { b.appendEncodedPath(segments.get(i)); } return b.build(); }
/** * Removes query parameter from an Uri, if present. * * @param uri The uri. * @param queryParameterName The name of the query parameter. * @return The uri without the query parameter. */ public static Uri removeQueryParameter(Uri uri, String queryParameterName) { Uri.Builder builder = uri.buildUpon(); builder.clearQuery(); for (String key : uri.getQueryParameterNames()) { if (!key.equals(queryParameterName)) { for (String value : uri.getQueryParameters(key)) { builder.appendQueryParameter(key, value); } } } return builder.build(); }
Uri.Builder builder = new Uri.Builder(); builder.scheme("https") .authority("www.myawesomesite.com") .appendPath("turtles") .appendPath("types") .appendQueryParameter("type", "1") .appendQueryParameter("sort", "relevance") .fragment("section-name"); String myUrl = builder.build().toString();