PHP cURL işleri POST, ama ben cURL olmadan POST değil ne zaman - ne eksik?

0 Cevap php

I am in a situation where I cannot use PHP cURL module to POST my form data. I have found a great blog post showing how to POST without using cURL here: HTTP POST from PHP, without cURL

İşte benim sorunum olsa bulunuyor. Ben POST isteği göndermeye çalıştığınızda, istek (diğer) sunucu vurur ama içeriği (POST verileri) yayın yapıyor. Diğer sunucu içeriği almaz. Ben cURL kullanmak yaparsam ANCAK, iyi çalışıyor. Ne eksik? Nasıl cURL kullanmadan cURL HTTP POST isteği yeniden olabilir?

İşte (form verilerini içeren sadece $ _POST olan $ this-> params) çalışır cURL kodu:

$ch = curl_init($this->url);

$params = http_build_query($this->params);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL

$result = curl_exec($ch);
curl_close($ch);

return $result;

Ve burada çalışmıyor benim olmayan-cURL versiyonu:

$postStr = http_build_query($this->params);

$opts = array(
    'http'=>array(
        'method' => $method,
        //'header' => 'Content-type: application/x-www-form-urlencoded',
        //'header' => 'content-type: multipart/form-data',
        'content-type' => 'application/x-www-form-urlencoded',
        'content-encoding' => 'UTF-8',
        'content' => $postStr
    )
);

$context = stream_context_create($opts);

$result = file_get_contents($this->url, false, $context);

return $result;

Hiçbir hata veya uyarı bulunmamaktadır. Sadece kabul sunucu içeriği görünmüyor. Herhangi bir fikir?

0 Cevap