How can I make a PUT request in cURL using Android Studio?

0

The request I want to make:

curl "https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id}?access_token=your-access-token" \

-X PUT \

-H "Content-Type: application/json" \

-d @file.geojson

This is my geojson:

{ 
  "id": "{feature_id}"
  "type": "Feature",
  "properties": {
    "calle": "lazaro cardenas",
    "nombre": "Palacio de Bellas Artes",
    "attendant": "ejemplo",
    "colonia": "Centro",
    "delegacion": "Benito Juarez",
    "tipoM": "Refugio",
    "id": "R-20170222",
    "numero": 23
  },
  "geometry": {
    "coordinates": [
      -99.14132,
      19.435637
    ],
    "type": "Point"
  }
}

The response will also return the geojson to verify the record.

And I have something like this in code:

public static String getRequest() {
        StringBuffer stringBuffer = new StringBuffer("");
        BufferedReader bufferedReader = null;
        try {
            SONObject json = new JSONObject();
            //example of json
            json.put("username", "miNombre");
            json.put("password", "miPassword");
            String s = json.toString();
            StringEntity se = new StringEntity(s,HTTP.UTF_8);

            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpPut = new HttpPut();

            URI uri = new URI("https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id}?access_token=your-access-token");
            httpPut.setURI(uri);
            httpPut.addHeader("Content-Type: application/json");
            httpPut.setEntity(se);

            HttpResponse httpResponse = httpClient.execute(httpPut);

            InputStream inputStream = httpResponse.getEntity().getContent();
            bufferedReader = new BufferedReader(new InputStreamReader(
                    inputStream));

            String readLine = bufferedReader.readLine();
            while (readLine != null) {
                stringBuffer.append(readLine);
                stringBuffer.append("\n");
                readLine = bufferedReader.readLine();
            }
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    // TODO: handle exception
                }
            }
        }
        return stringBuffer.toString();
}
    
asked by Eduardo Gomez 19.04.2018 в 17:27
source

0 answers