欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php采用file_get_contents代替使用curl實例

 更新時間:2014年11月07日 11:43:53   投稿:shichen2014  
這篇文章主要介紹了php采用file_get_contents代替使用curl的方法,實例講述了file_get_contents模擬curl的post方法,對于服務器不支持curl的情況來說有一定的借鑒價值,需要的朋友可以參考下

本文實例講述了php采用file_get_contents代替使用curl的方法,分享給大家供大家參考。具體實現(xiàn)方法如下:

file_get_contents代替使用curl其實不多見了,但有時你碰到服務器不支持curl時我們可以使用file_get_contents代替使用curl,下面看個例子。

當用盡一切辦法發(fā)現(xiàn) 服務器真的無法使用curl時?;蛘遚url不支持https時。curl https 出現(xiàn)502時。你又不想重裝網(wǎng)站環(huán)境的時候,你就改用file_get_contents 代替吧。
curl 經(jīng)常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:

復制代碼 代碼如下:
function Post($url, $post = null) {      
        $content = http_build_query($post);
        $content_length = strlen($content);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' =>"Content-type: application/x-www-form-urlencoded",
                'content' => $post
            )
        );
        return file_get_contents($url, false, stream_context_create($options));
}

希望本文所述對大家的php程序設計有所幫助。

相關文章

最新評論