Using POST to simulate GET


The GET request is used for getting the representation of the resource. When sending a GET request, it requires to give parameters in the URI. Different operations on different resources need different parameters. Therefore, it is possible that the URI may be too long because of too many parameters. For example, the response may fail because there are so many measuring points that the URI is too long.

SuperMap iServer provides the solution to this situation: using POST to GET. The parameters are not placed in the URI, but the request body of the POST request. And then, add "_method= GET" at the end of the URI for the POST request.

Implementing the GET request on the distance resource can get the distance on the map based on the given parameters. Below is the example of using the POST request to simulate the GET request (json format). The compete HTTP request is as follows:

POST /iserver/services/components-rest/rest/maps/WorldMap/distance.json?_method=GET HTTP/1.1

Host: supermapiserver:8090

Content-Length: 96

 

{"point2Ds":[{"x": 23.00,"y":34.00},{"x":53.55,"y":12.66},{"x": 73.88,"y":12.6}],"unit":"METER"}

In the request line, "_method= GET" after the URI indicates the POST request simulates GET request. The parameters point2Ds and unit needed by the original GET request are placed in the request body of the POST request, expressed as a JSON string in the form of "parameter name 1": parameter value 1, "parameter name 2": parameter value 2,…….