curl ile bir url tepki değerini almak

1 Cevap php

Ben bir dize türü yanıt almak için PHP curl yöntemi kullanıyorum. Ben kullanmak isteği oluşturmak için:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, $data);

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if($response === false)
    throw new Exception(__CLASS__."::".__FUNCTION__."_".$err);
return $response;

Neden hep bir bool (true) tepki yerine ben diğer taraftan yankı dize almak?

Teşekkürler

1 Cevap

Zaten bu yana

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

kodunuzda. curl_exec yerine zaten bir BOOL sayfasının içeriğini döndürür gerekir.

Bu kullandığım bir kütüphane bir pasajı. Işaret ettiği gibi, bu gerekli olmayabilir ama bir zamanlar bana yardımcı oldu ...

//The content - if true, will not download the contents
curl_setopt($ch, CURLOPT_NOBODY, false);

Ayrıca CURLOPT_NOBODY (bu sorunu neden olan açıklayabilir) ile ilgili bazı hatalar var gibi görünüyor: