The requested resource does not support http method 'POST' - PHP
<p>I am trying to send string values to other php file, using CURLOPT_POST method, but getting the result as 
{"Message":"The requested resource does not support http method 'POST'."}    </p>

<pre><code>&lt;?php 
            // create curl resource 
            $ch = curl_init("http://localhost/data.php"); 

            // set url 
            curl_setopt($ch, CURLOPT_URL, "http://nginx.api.askmegrocery.com/api/products/INDLSOUT001/571/0/0/0/2000/1"); 

            //return the transfer as a string 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

            // $output contains the output string 
            $output = curl_exec($ch); 

            $arrayvar=json_decode($output,true);

            //var_dump($arrayvar);
            for($row = 0; $row&lt;1; $row++){

                var_dump( $arrayvar[$row]);

                $string = http_build_query($arrayvar[$row]);
                echo $string;
                curl_setopt($ch, CURLOPT_POST,true);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$string);

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                //curl_exec($ch);
                $result = curl_exec($ch);
                print_r($result) ;
            }

            // close curl resource to free up system resources 
            curl_close($ch);  


    ?&gt;
</code></pre>

<p>When i echo $string , i get the following output, which is exactly what i want</p>

<pre><code>Brand=Dabur&amp;Displaytitle=Dabur+Glucon-D+1+kg&amp;Name=Energy+Drinks&amp;CategoryID=594&amp;VariantID=17251&amp;Itemid=1547358&amp;CP=150&amp;MRP=150&amp;PctOff=0&amp;Shippingcharges=0.00
</code></pre>