卷曲 - 如何处理响应

时间:2013-07-06 11:17:29

标签: php curl

我正在使用它将一些信息发送到另一个网站并且工作正常

function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) { 
  $fields .= $key . '=' . $value . '&'; 
}
rtrim($fields, '&');

$post = curl_init();

curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);

$result = curl_exec($post);

curl_close($post);
}

$data = array(
"api_key" => "****",
"api_password" => "****",
"notify_url" => "www.mysite.com",
"order_id" => "$orderid2",
"cat_1" => "$cat_1",
"item_1" => "$item1",
"desc_1" => "$desc_1",
"qnt_1" => "$qty1",
"price_1" =>"$up1",                                                  
"cat_2" => "$cat_2",
"item_2" => "$item2",
"desc_2" => "$desc_2",
"qnt_2" => "$qty2",
"price_2" => "$up2",    


);

post_to_url("http://website2.com/submitorder.php", $data);

当website2收到信息时,它会发回一个xml,回复“OK-Data Received”,它出现在我的页面上。我可以做些什么来阻止我的页面上显示此消息,以便使用该网站的人看不到它?

2 个答案:

答案 0 :(得分:4)

您必须设置CURLOPT_RETURNTRANSFER设置:

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

这样,curl_exec($c)将返回输出,而不是将其传递给浏览器。


  

<强> CURLOPT_RETURNTRANSFER
  TRUE将传输作为curl_exec()返回值的字符串返回,而不是直接输出。

答案 1 :(得分:0)

将选项设置为:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);