国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php采用file_get_contents代替使用curl實例

2024-05-04 23:27:02
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了php采用file_get_contents代替使用curl的方法,實例講述了file_get_contents模擬curl的post方法,對于服務器不支持curl的情況來說有一定的借鑒價值,需要的朋友可以參考下
 
 

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

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

當用盡一切辦法發現 服務器真的無法使用curl時。或者curl不支持https時。curl https 出現502時。你又不想重裝網站環境的時候,你就改用file_get_contents 代替吧。
curl 經常使用的 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程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高阳县| 修文县| 贺州市| 德惠市| 卢氏县| 墨江| 新宁县| 鄱阳县| 内江市| 涟源市| 乌苏市| 兴安盟| 靖江市| 吉安县| 淮北市| 河北省| 贡觉县| 吉安县| 天峻县| 青川县| 大余县| 琼结县| 枣阳市| 黔西| 安远县| 中宁县| 大兴区| 孟津县| 定边县| 云和县| 乐东| 景泰县| 于都县| 菏泽市| 景德镇市| 洮南市| 商丘市| 麻江县| 丰宁| 德化县| 萨迦县|