我正在尝试使用CURLOPT_POST方法将字符串值发送到其他php文件,但是将结果作为 {“消息”:“请求的资源不支持http方法'POST'。”}
<?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<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);
?>
当我回显$ string时,我得到以下输出,这正是我想要的
Brand=Dabur&Displaytitle=Dabur+Glucon-D+1+kg&Name=Energy+Drinks&CategoryID=594&VariantID=17251&Itemid=1547358&CP=150&MRP=150&PctOff=0&Shippingcharges=0.00