2015-04-12 79 views
0

我使用捲曲發送端口的請求,而不使用此代碼使用curlto總是發送POST請求輸出

$data = array('username' => 'username', 'password' => 'password'); 
$url = 'http://urlhere'; 
$ch = curl_init($url); 
$postString = http_build_query($data, '', '&'); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
// or use this line curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
$response = curl_exec($ch); 
curl_close($ch); 

我用1和真正的代碼的最後一行打印結果的結果,但它總是在網頁上打印結果。如何執行curl而不輸出結果?

回答

1

,因爲我在我的日常項目中使用相同的代碼並取回數據沒有得到印刷

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
+0

最後一行幫助非常感謝必須工作。 –