• My dev site’s WP is returning the home page HTML rather than passing a POST request to a plugin!

    I have MAMP 4.1.1 installed and need to develop PHP scripts outside of WP to communicate with a WP plugin (WooCommerce Software License by Nsp-Code). On my actual site and on my laptop, the plugin’s responses are returned normally, but on my desktop dev site, the POST requests return the HTML of the home page. Both Macs are configured the same, running Sierra 10.12.3, same WordPress setup; the only likely difference being the PHP mail settings (using smtp_catcher on the iMac). It would be nice if that could be fixed with a simple setting in wp-config.php but I suspect the most likely way around it is a POST-only PHP script to target instead of the index.php.

    If there’s no simple fix, does a PHP script exist to dispatch POSTs but never return HTML?

    8-\

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter rickjohnsongraffix

    (@rickjohnsongraffix)

    I contacted the developer of smtp_catcher and he says I’m the first person to report POSTs returning the site’s HTML; it works for him and others because it only touches PHP mail. What kinds of things could cause a POST or GET request (not a blog post, a data HTML POST to a plugin’s API) to return the home page HTML?

    I installed my dev site by exporting the live site via WordPress > Tools > Export, then Themes > Export. Installed WP fresh on dev site, created a new empty database, added purchased theme and plugins, imported WP export, then imported theme data. Even re-installed MAMP several times.

    I’ve been struggling for a year to go online with new products and communication with the WP plugin’s API is the last piece to finish, but as-is I can make zero progress. I’d be extremely grateful for any suggestions!

    Dion

    (@diondesigns)

    Are you sure your POST request is actually reaching the plugin? I’m wondering if this could be some sort of webserver (Apache/nginx/ec) issue with redirects or URL rewrites.

    This could also be caused by a plugin that alters how WordPress parses URLs. I’ve seen some “security” plugins that strip the $_GET, $_POST, and $_REQUEST arrays of things they think are malicious. What they do instead is break other plugins and offer no added security.

    Thread Starter rickjohnsongraffix

    (@rickjohnsongraffix)

    Thanks for the response, Dion. I’m pretty sure the request is not reaching the plugin. My script does a var_dump and nothing from the plugin appears on the page. Last night I re-installed MAMP and tonight I reinstalled the OS (Sierra). I also made a new installation of WordPress without importing any settings from the live site, thinking maybe it was somehow confused about which database to use. I activated only the minimum plugins, and again the response to the script’s POST is the HTML for the site.

    My sense is that the problem relates to the system file editing to enable PHP mail from a local server (which didn’t work), even though it doesn’t make sense that mail is really related. After reinstalling the OS, the smtp_catcher still worked, so I suspect not all system files were restored. I’m hesitant to do a complete reformat and clean rebuild of my drive, hoping that a PHP script can be added to WP that does nothing but pass POSTs to WP, just a temporary workaround for the dev site only. Now I’m wishing I’d have bought a bigger backup drive to include the entire drive so I could just revert to a day before this mess occurred! (Lesson learned)

    Thread Starter rickjohnsongraffix

    (@rickjohnsongraffix)

    Using Postman to send identical POSTs on the laptop and desktop, the one that returns the HTML of the entire page includes a couple of additional items in its response header:

    Link →<https://localhost:8888/wordpress/wp-json/>; rel="https://api.w.org/"
    Link →<https://localhost:8888/wordpress/>; rel=shortlink

    Searching the web, this seems to indicate a problem with REST, although this is a fresh WP/WooCommerce install with a generic 2017 theme, and REST is enabled in WC’s settings. I’ve found that Ajax errors can cause this, but I don’t see how that could apply here given it works perfectly on the laptop.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘external POST request to WP returns HTML’ is closed to new replies.