php curl: ben basit bir mesaj istek ve sayfa örnek retrival gerekir

4 Cevap php

i curl sonrası bir isteği göndermek ve cevap sayfası almak için bilmek istiyorum

teşekkürler

4 Cevap

Ne bu böyle bir şey:

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://www.example.com/yourscript.php",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'field1' => 'some date',
        'field2' => 'some other data',
    )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

// result sent by the remote server is in $result


For a list of options that can be used with curl, you can take a look at the page of curl_setopt.

Burada, kullanmak zorunda, en azından olacak:

  • CURLOPT_POST: Bir POST isteği, bir GET göndermek istediğiniz gibi
  • CURLOPT_RETURNTRANSFER: Eğer curl_exec isteği sonucu dönmek, ya da isteyip istemediğinize bağlı olarak, o sadece çıktı.
  • CURLOPT_POSTFIELDS: asılacaktır verileri - bir sorgu dizesi gibi dize, ya da bir dizi kullanarak direkt olarak yazılmış olabilir


And don't hesitate to read the curl section of the PHP manual ;-)

açıklamalarda birini deneyin: http://php.net/manual/en/curl.examples-basic.php

(Ancak 1) bunu yerine get bir yazı yapmak için, ($ ch, CURLOPT_POST curl_setopt ekleyin)

ya da bu örnek: http://php.dzone.com/news/execute-http-post-using-php-cu

Ben eklemek gerektiğini düşünüyorum

curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $postFields);

Sen CURLOPT_POST kullanarak gönderebilir ve onunla veri aktarmak istiyorsanız, kullanmak isteği ayarlamanız gerekir CURLOPT_POSTFIELDS:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$data = array(
    'username' => 'foo',
    'password' => 'bar'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$contents = curl_exec($ch);

curl_close($ch);