InputStream stream = new URL (params [0]). openStream ();

1

I need to send an additional variable to the url, my code is this

private final String mGeoJsonUrl = "http://181.XXX.XXX.XXX:8080/MIPAGINA.php?id=" + id ;

protected void start() {
    DownloadGeoJsonFile downloadGeoJsonFile = new DownloadGeoJsonFile();
    // Download the GeoJSON file
    downloadGeoJsonFile.execute(mGeoJsonUrl);
}

protected JSONObject doInBackground(String... params) {
        try {
           // List params = new ArrayList();
            // getting JSON string from URL
            // Open a stream from the URL
            InputStream stream = new URL(params[0]).openStream();
           // JSONObject json = jParser.makeHttpRequest(mGeoJsonUrl, "GET", params);

            String line;
            StringBuilder result = new StringBuilder();
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

            while ((line = reader.readLine()) != null) {
                // Read and save each line of the stream
                result.append(line);
            }
            // Close the stream
            reader.close();
            stream.close();
            // Convert result to JSONObject
            return new JSONObject(result.toString());
        } catch (IOException e) {
            Log.e(mLogTag, "GeoJSON file could not be read");
        } catch (JSONException e) {
            Log.e(mLogTag, "GeoJSON file could not be converted to a JSONObject");
        }
        return null;
    }
    
asked by oscar j 06.07.2016 в 23:56
source

1 answer

0

If you want to send an additional parameter in a GET Request simply add it in the url, for example if you want to send the value of the variable titulo , this would be the form

String miTitulo = "StackOverflow";

private final String mGeoJsonUrl = "http://181.XXX.XXX.XXX:8080/MIPAGINA.php?id=" + id + "&titulo=" + miTitulo;

Remember that the first variable is added to the url with ? and the following variables are concatenated with & .

    
answered by 09.07.2016 в 22:07