Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp post request to webservice
    text
    copied!<p>I have a web service that works fine with get requests but trying to use post it doesn't seem to work. I have this in my routes:</p> <pre><code>Router::connect("/products/service_add", array("controller"=&gt;"products", "action" =&gt; "service_add", 'seller'=&gt;true, "[method]" =&gt; "POST")); </code></pre> <p>Seller is like an admin. I also have ParseExtensions('xml'). My action is:</p> <pre><code> function seller_service_add() { $this-&gt;log("hit", 'debug'); $hi = array("message"=&gt;"hey"); $this-&gt;set(compact('hi')); } </code></pre> <p>and the view is:</p> <pre><code>&lt;product&gt; &lt;?php echo $xml-&gt;serialize($hi); ?&gt; &lt;/product&gt; </code></pre> <p>When I try to send a post to the API I just get a debug trace back with timer info. In the same script as I'm doing the post request I'm doing a get and when I run the script I can see the data passed by the API for the get but not for the post request. </p> <p>The code I'm using to send the post is:</p> <pre><code>$ch = curl_init(); $data = array('Your' =&gt; 'Data'); curl_setopt($ch, CURLOPT_URL, "http://localhost/&lt;project&gt;/products/service_add.xml"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $result = curl_exec($ch); curl_close($ch); print_r($result);` </code></pre> <p>Any ideas on why this isn't working? Any help would be much appreciated.</p> <p>Sorry if this is a bit verbose!</p> <p>Update: I've added lines to spit stuff out to the cakephp debug log when actions are hit. I have one entry on the beforeFilter, this entry gets hit and I can see it in the log. The entry in the service_add action is not present in the log so I guess that the action is not being hit?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload