Android - get json with variables in path

138 views Asked by At

how can I set variables in url to get json in Android? In most tutorials is method like this:

public String makeServiceCall(String reqUrl) {
    String response = null;
    try {
        URL url = new URL(reqUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        // read the response
        InputStream in = new BufferedInputStream(conn.getInputStream());
        response = convertStreamToString(in);
    } catch (MalformedURLException e) {
        Log.e(TAG, "MalformedURLException: " + e.getMessage());
    } catch (ProtocolException e) {
        Log.e(TAG, "ProtocolException: " + e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "IOException: " + e.getMessage());
    } catch (Exception e) {
        Log.e(TAG, "Exception: " + e.getMessage());
    }
    return response;
}

Where requURL is String, for example: http://192.168.1.3:5000/test. And what if I want to set in this URL variable? For example, http://192.168.1.3:5000/test/{id}, where id is Integer. I dont want use parameters, I want use variables in path. It is possible?

Thanks in advance. :)

0

There are 0 answers