jqueryweb-servicesfiwarefiware-wirecloud

HTTP POST request gets transformed to GET request


How exactly does the WireCloud proxy work? We use the following code for a request via the WireCloud proxy:

MashupPlatform.http.makeRequest(url, {
        method: 'POST',
        forceProxy: true,
        onSuccess: function (response) {
            success(response);
        },
        onFailure: function (response) {
            error(response);
        },
        onComplete: function () {
            complete();
        }
    });

The browser network analysis shows that a POST request gets send to https://example.com/cdp/https/rest.example.com/path/to/service. Our webservice that gets called by the url however logs, that it receives a GET request.

The access log of our rest service hosted by a tomcat shows:

192.168.60.221 - - [26/May/2016:10:38:31 +0200] "GET /path/to/service HTTP/1.1" 405 1013
192.168.60.221 - - [26/May/2016:10:38:42 +0200] "POST /path/to/service HTTP/1.1" 204 -

The first call is done with the MashupPlatform.http.makeRequest call listed above, the second call is done with jQuery like this:

$.ajax({
        type: "POST",
        url: url,
        data: null,
        success: success
    });

This works perfeclty fine when we set the CORS header in our webservice.

So what may be the reason, that WireClouds proxy does not work as expected?


Solution

  • There are a lot of widgets and operators using the MashupPlatform API and the WireCloud's CORS proxy and we have never see it transforming POST requests into GET requests. Anyway, it's fine to use jQuery ;-). Moreover, you can also use it for performing requests to services not supporting the CORS headers by using the buildProxyURL method. E.g:

    url = MashupPlatform.http.buildProxyURL('https://api.example.com/api/endpoing');
    $.ajax({
        method: "POST",
        url: url,
        data: null,
        success: success
    });