Java tutorial
//package com.java2s; /* * Project: NextGIS Mobile * Purpose: Mobile GIS for Android. * Author: Stanislav Petriakov, becomeglory@gmail.com * ***************************************************************************** * Copyright (c) 2017 NextGIS, info@nextgis.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.text.TextUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import javax.net.ssl.HttpsURLConnection; public class Main { private static String getData(String target, String method, String token) { try { URL url = new URL(target); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); if (!TextUtils.isEmpty(token)) conn.setRequestProperty("Authorization", token); conn.setRequestMethod(method); conn.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line, data = ""; while ((line = in.readLine()) != null) data += line; in.close(); return data; } catch (IOException ignored) { ignored.printStackTrace(); } return null; } }