如何在没有卷曲的情况下发帖请求?

dyn*_*mic 5 php http

考虑到我不想使用curl,这是一个有效的替代方案来发布帖子请求?也许Zend_http_client

我只需要基本的东西(我需要一个只有一个帖子参数的网址)

Aud*_*sen 32

您可以使用file_get_contents().

PHP手册在这里有一个很好的例子.这只是从手册中复制过来的:

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);
$context  = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
Run Code Online (Sandbox Code Playgroud)


Sau*_*tel 7

您可以使用stream_context_createfile_get_contents

<?php
$context_options = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
            )
        );
?>


$context = stream_context_create($context_options); 
$result = file_get_contents('http://www.php.net', false, $context);
Run Code Online (Sandbox Code Playgroud)


Daf*_*aff -1

如果您已经在使用 Zend Framework,您应该尝试您提到的Zend_Http_Client

$client = new Zend_Http_Client($host, array(
            'maxredirects' => 3,
            'timeout'      => 30));
$client->setMethod(Zend_Http_Client::POST);
// You might need to set some headers here
$client->setParameterPost('key', 'value');
$response = $client->request();
Run Code Online (Sandbox Code Playgroud)