We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34004
    • 125 Posts
    I have a MODX website which I would like to HTTP POST data to. I imagine I then have to build a web service to take the POST data, insert it into the DB and send a 200 OK response back. I have googled around and I can't quite seem to find a good place to start. Some PHP tutorials say I have to modify .htaccess to add mod_rewrite rules, but it's a bit vaue when integrating with MODx.

    I could use GET and pass query strings however this particular web service that is sending the data only supports POST, and that's the right way to do it anyway.

    Below is the data I am posting to the server (just two, a value and a timestamp):

    HEADERS
    Content-Length: 342
    User-Agent: iCody/3.0.7 CFNetwork/672.1.14 Darwin/14.0.0
    Accept-Language: en-gb
    Host: requestb.in
    Accept: */*
    Connection: close
    Content-Type: application/x-www-form-urlencoded
    X-Request-Id: 9e39eb13-4551-4f6a-bc83-7d018fff812c
    Accept-Encoding: gzip

    FORM/POST PARAMETERS
    timestamp: 1398541820
    value: 555

    Can anyone set me on the right path to building a web service to receive HTTP POST data sending the right HTTP response back?

    [ed. note: ficklelife last edited this post 12 years, 5 months ago.]
      • 3749
      • 24,544 Posts
      It sounds to me like all you need is a resource with a snippet tag on it. Maybe I'm missing something.

      The snippet can return an empty string unless the $_POST contains the proper authentification info. When it does, the snippet can sanitize the $_POST array, extract the data from it and write it to the DB, and if desired, return an indication that things were successful.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting