6 Replies Latest reply on Dec 1, 2016 11:14 AM by jasong RSS
    richardwi Explorer

    Specifying request headers in ContentLoader functions

    I've created a service that tries to load and return JSON from a URL that needs the "Accept: application/json" header in order to return JSON.

    var params = {
        url: url,
        headers: {Accept:"application/json"}
    };
    var result = Resources["ContentLoaderFunctions"].LoadJSON(params);

    That's basically all it is.  I've tested the URL using Postman and it does indeed return JSON, e.g.:

    [{"time":"Wed, 09 Nov 2016 01:22:14 GMT","value":"87"}]

    Without the "Accept" header, it returns XML.

    However, I cannot get my service to return the JSON object!  Have I specified the header incorrectly?  The LoadJSON snippet says the type of the "headers" parameter is "JSON"; this suggests that what I've done is wrong, since I've used a JavaScript object.  The JSON would be:

    "{\"Accept\":\"application/json\"}"

    (i.e. a JSON-encoded string) but I've tried this too and got the same result, which is an empty response.  At least that's how it looks via the [Test] button.

    What am I doing wrong?!