Ignore:
Timestamp:
2017-08-13T00:24:03+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #15141 - Make HTTP POST requests to Overpass API - allows longer/more complex queries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r12542 r12596  
    66import java.io.IOException;
    77import java.io.InputStream;
     8import java.nio.charset.StandardCharsets;
    89import java.util.EnumMap;
    910import java.util.Map;
     
    3536 */
    3637public class OverpassDownloadReader extends BoundingBoxDownloader {
     38
     39    private static final String DATA_PREFIX = "?data=";
    3740
    3841    static final class OverpassOsmReader extends OsmReader {
     
    144147            final String query = this.overpassQuery.replace("{{bbox}}", lat1 + "," + lon1 + "," + lat2 + "," + lon2);
    145148            final String expandedOverpassQuery = expandExtendedQueries(query);
    146             return "interpreter?data=" + Utils.encodeUrl(expandedOverpassQuery);
     149            return "interpreter" + DATA_PREFIX + Utils.encodeUrl(expandedOverpassQuery);
    147150        }
    148151    }
     
    195198                                            boolean uncompressAccordingToContentDisposition) throws OsmTransferException {
    196199        try {
    197             return super.getInputStreamRaw(urlStr, progressMonitor, reason, uncompressAccordingToContentDisposition);
     200            int index = urlStr.indexOf(DATA_PREFIX);
     201            // Make an HTTP POST request instead of a simple GET, allows more complex queries
     202            return super.getInputStreamRaw(urlStr.substring(0, index),
     203                    progressMonitor, reason, uncompressAccordingToContentDisposition,
     204                    "POST", Utils.decodeUrl(urlStr.substring(index + DATA_PREFIX.length())).getBytes(StandardCharsets.UTF_8));
    198205        } catch (OsmApiException ex) {
    199206            final String errorIndicator = "Error</strong>: ";
Note: See TracChangeset for help on using the changeset viewer.